* [email protected] ([email protected]) wrote:
> From: Simon Marchi <[email protected]>
>
> This allows to list the command-specific options in order to make more
> accurate bash completion.
>
> Signed-off-by: Simon Marchi <[email protected]>
[...]
> @@ -454,6 +459,10 @@ int cmd_add_context(int argc, const char **argv)
> }
> free(tmp);
> break;
> + case OPT_LISTOPTS:
> + list_cmd_options(stdout, long_options);
> + ret = CMD_SUCCESS;
> + goto end;
> default:
text alignment problem. (repeated in each cmd_* function in the other
files)
> +/*
> + * list_cmd_options
> + *
> + * Prints a simple list of the options available to a command. This is
> intended
> + * to be easily parsed for bash completion.
> + */
> +void list_cmd_options(FILE *ofp, struct poptOption *options)
> +{
> + int i = 0;
Spaces should be turned into a tab here.
> + struct poptOption *option = NULL;
> +
> + option = &options[i];
> + while (option->longName != NULL) {
for (i = 0; options[i]->longname != NULL; i++) {
option = &options[i];
....
}
would be clearer than the while() construct here I think.
Thanks,
Mathieu
> + fprintf(ofp, "--%s\n", option->longName);
> +
> + if (isprint(option->shortName)) {
> + fprintf(ofp, "-%c\n", option->shortName);
> + }
> +
> + i++;
> + option = &options[i];
> + }
> +}
> +
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev