forked from drath/libratbag
tools: return the right error from device_from_arg
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -140,29 +140,30 @@ usage(void)
|
||||
" --help .......... Print this help.\n");
|
||||
}
|
||||
|
||||
static inline struct ratbag_device *
|
||||
static inline int
|
||||
ratbag_cmd_device_from_arg(struct ratbag *ratbag,
|
||||
int *argc, char **argv)
|
||||
int *argc, char **argv,
|
||||
struct ratbag_device **device_out)
|
||||
{
|
||||
struct ratbag_device *device;
|
||||
const char *path;
|
||||
|
||||
if (*argc == 0) {
|
||||
error("Missing device path.\n");
|
||||
usage();
|
||||
return NULL;
|
||||
return ERR_USAGE;
|
||||
}
|
||||
|
||||
path = argv[*argc - 1];
|
||||
device = ratbag_cmd_open_device(ratbag, path);
|
||||
if (!device) {
|
||||
error("Device '%s' is not supported\n", path);
|
||||
return NULL;
|
||||
return ERR_DEVICE;
|
||||
}
|
||||
|
||||
(*argc)--;
|
||||
*device_out = device;
|
||||
|
||||
return device;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
static inline struct ratbag_profile *
|
||||
@@ -216,12 +217,14 @@ fill_options(struct ratbag *ratbag,
|
||||
struct ratbag_device *device = options->device;
|
||||
struct ratbag_profile *profile = options->profile;
|
||||
struct ratbag_resolution *resolution = options->resolution;
|
||||
int rc;
|
||||
|
||||
if ((flags & (FLAG_NEED_DEVICE|FLAG_NEED_PROFILE|FLAG_NEED_RESOLUTION)) &&
|
||||
device == NULL) {
|
||||
device = ratbag_cmd_device_from_arg(ratbag, argc, argv);
|
||||
if (!device)
|
||||
return ERR_DEVICE;
|
||||
rc = ratbag_cmd_device_from_arg(ratbag, argc, argv,
|
||||
&device);
|
||||
if (rc != SUCCESS)
|
||||
return rc;
|
||||
options->device = device;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user