switch (op)
{
case '+':
- if (!options->from(options, optarg, &argc, &argv, optind))
- {
- /* a error value */
- return 255;
- }
- continue;
case 'v':
- dbg_default_set_level(atoi(optarg));
- continue;
case 'u':
- uri = optarg;
continue;
default:
*arg = optarg;
options->destroy(options);
}
+/**
+ * Process options common for all commands
+ */
+static bool process_common_opts()
+{
+ while (TRUE)
+ {
+ switch (getopt_long(argc, argv, command_optstring, command_opts, NULL))
+ {
+ case '+':
+ if (!options->from(options, optarg, &argc, &argv, optind))
+ {
+ return FALSE;
+ }
+ continue;
+ case 'v':
+ dbg_default_set_level(atoi(optarg));
+ continue;
+ case 'u':
+ uri = optarg;
+ continue;
+ default:
+ continue;
+ case '?':
+ return FALSE;
+ case EOF:
+ return TRUE;
+ }
+ }
+}
+
/**
* Open vici connection, call a command
*/
{
return command_usage(NULL);
}
+ if (!process_common_opts())
+ {
+ return command_usage("invalid options");
+ }
+ optind = 2;
return call_command(&cmds[i]);
}
}