Add support for using an optional device descriptor

The device descriptor is either mandatory for a certain command (with
DCTOOL_CONFIG_DESCRIPTOR) or always NULL. But for some commands it will
be useful to support an optional descriptor as well. To support this, we
always try to lookup the device descriptor whenever the corresponding
command-line options are set.
This commit is contained in:
Jef Driesen 2018-03-18 10:43:14 +01:00
parent 0026fbd289
commit 54fef8e093

View File

@ -275,14 +275,7 @@ main (int argc, char *argv[])
dc_context_set_loglevel (context, loglevel); dc_context_set_loglevel (context, loglevel);
dc_context_set_logfunc (context, logfunc, NULL); dc_context_set_logfunc (context, logfunc, NULL);
if (command->config & DCTOOL_CONFIG_DESCRIPTOR) { if (device != NULL || family != DC_FAMILY_NULL) {
// Check mandatory arguments.
if (device == NULL && family == DC_FAMILY_NULL) {
message ("No device name or family type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Search for a matching device descriptor. // Search for a matching device descriptor.
status = dctool_descriptor_search (&descriptor, device, family, model); status = dctool_descriptor_search (&descriptor, device, family, model);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
@ -304,6 +297,13 @@ main (int argc, char *argv[])
} }
} }
// Check mandatory descriptor arguments.
if (command->config & DCTOOL_CONFIG_DESCRIPTOR && descriptor == NULL) {
message ("No device name or family type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Execute the command. // Execute the command.
exitcode = command->run (argc, argv, context, descriptor); exitcode = command->run (argc, argv, context, descriptor);