[ltt-dev] [lttng-tools PATCH] Add list-options to all commands

Mathieu Desnoyers compudj at krystal.dyndns.org
Thu Aug 4 15:18:54 EDT 2011


* simon.marchi at polymtl.ca (simon.marchi at polymtl.ca) wrote:
> From: Simon Marchi <simon.marchi at ericsson.com>
> 
> This allows to list the command-specific options in order to make more accurate bash completion.
> 
> Signed-off-by: Simon Marchi <simon.marchi at polymtl.ca>
[...]

> @@ -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




More information about the lttng-dev mailing list