[sheepdog] [PATCH 0/6] introduce sd_getopt to parse command line options

MORITA Kazutaka morita.kazutaka at gmail.com
Mon Nov 5 17:02:43 CET 2012


At Mon, 05 Nov 2012 22:48:41 +0800,
Liu Yuan wrote:
> 
> On 11/05/2012 06:51 PM, morita.kazutaka at gmail.com wrote:
> > This series introduces sd_getopt to parse command line options, which
> > aims for us to maintain sheep options easily.  With this patch, what
> > we need to do to add a command line option is only modifying a
> > sheep_option variable; short options, long options, and help message
> > will be automatically generated.
> > 
> > All command options must follow the folllowing syntax.
> >   --<option> [<arg>[:<key>=<value>[,<key>=<value>[,...]]]]
> 
> generalized as '--<option> [<prefix>[:<key>=<value>[,<key>=<value>[,...]]]]
> 
> besides sd_opt_get_value(key), I'd suggest add yet another helper named
> sd_opt_get_prefix(opt). 'opt->arg.str' isn't self-explanatory.

'prefix' sounds a bit strange to me because most of options doesn't
require <key>=<value> pairs.  For example, when '-p 7000' or '-c
corosync' is given, calling '7000' or 'corosync' prefix isn't strange?
I think that <key>=<value> pairs are just attributes.  Rather than
generalizing syntax, I think enumerating acceptable syntaxes looks
easy to understand:

  [no arugment]
  --<option>
  --<option> <key>=<value>[,<key>=<value>[,...]]

  [require arugment]
  --<option> <arg>
  --<option> <arg>:<key>=<value>[,<key>=<value>[,...]]

Or, if we wouldn't keep backward compatibility at all, the following
syntax might be better.

  --<option> [option[,option[,...]]]

    where option is <arg> or <key>=<value>.

Thanks,

Kazutaka



More information about the sheepdog mailing list