These can be replaced by adding a special option with the name G_OPTION_REMAINING and a callback that sets an error. Then, glib does all the work for us. Currently, it looks like crm_resource, crm_shadow, and cibadmin are still doing this.
Description
Description
Event Timeline
Comment Actions
crm_resource already uses G_OPTION_REMAINING to collect the remaining arguments into an array. Then after parsing all options, it logs those remaining arguments if they're invalid. However, they're valid if we're running a subcommand that uses options.override_params.
While we're parsing the arguments, we don't know what the command will end up being, so we don't know whether non-option arguments are valid. GLib collects the "remaining" options one-by-one as it's parsing the whole argv.
It doesn't look like cibadmin or crm_shadow support non-option arguments, so we might be able to use an approach like that there. It depends on what you have in mind.
- Set a callback that throws an error (or appends to the error) for each "remaining" option as it's parsed. This would require returning TRUE (indicating that the option validates during parsing), so that we can continue parsing the rest of the options and catching any additional "remaining" options.
- Set a callback that throws a error for just the first "remaining" option. That way we can return FALSE, causing option parsing to bail out with a failure.
- Collect the "remaining" options into a string array like crm_resource is currently doing, and log errors for them after option parsing.
- Something else.