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

morita.kazutaka at gmail.com morita.kazutaka at gmail.com
Mon Nov 5 11:51:57 CET 2012


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

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>[,...]]]]

E.g.
  -d
  -p 7001
  -c zookeeper:server=xx.xx.xx.xx,yy.yy.yy.yy
  -w object:size=100M,directio=true

This patch breaks backward compatibility a bit:

 - object cache size (-w object:size=xxx) and free diskspace size (-s
   xxx) must be specified in bytes or value with a suffix (K, M, G, or
   T).  For example,

   [before]
     -w object:size=100
     -s 1024

   [after]
     -w object:size=100M
     (or size=1024K, size=1048576)
     -s 1G
     (or -s 1024M, -s 1048576K, or -s $((1024 ** 3)))

 - option parameters must be key and value pairs.

   [before]
     -w object:directio

   [after]
     -w object:directio=on
     (or directio=1, directio=true, directio=t)

 - zookeeper and accord options need "server=" arguments

   [before]
     -c zookeeper:10.0.0.1:9000,10.0.0.2:9000,10.0.0.3:9000
     -c accord:10.0.0.1

   [after]
     -c zookeeper:server=10.0.0.1:9000,10.0.0.2:9000,10.0.0.3:9000
     -c accord:server=10.0.0.1

Thanks,

Kazutaka


MORITA Kazutaka (6):
  collie: move options to lib
  sheep: use sd_option for handling command line options.
  introduce sd_getopt as an alternative to getopt_long
  use sd_getopt instead of getopt_long
  sheep: show auto-generate help when invalid options are specified
  tests: specify size with a suffix

 collie/cluster.c          |   44 +++---
 collie/collie.c           |  119 ++++++-----------
 collie/collie.h           |   10 +-
 collie/debug.c            |    2 +-
 collie/vdi.c              |   50 ++++---
 include/option.h          |   77 +++++++++++
 include/util.h            |    1 +
 lib/Makefile.am           |    3 +-
 lib/option.c              |  278 ++++++++++++++++++++++++++++++++++++++
 lib/util.c                |   10 ++
 sheep/cluster.h           |   10 +-
 sheep/cluster/accord.c    |   13 +-
 sheep/cluster/corosync.c  |    3 +-
 sheep/cluster/local.c     |    9 +-
 sheep/cluster/zookeeper.c |   13 +-
 sheep/sheep.c             |  324 +++++++++++++++++++--------------------------
 sheep/sheep_priv.h        |    2 +-
 tests/010                 |    4 +-
 tests/016                 |    2 +-
 tests/018                 |    2 +-
 tests/019                 |    2 +-
 tests/020                 |    2 +-
 tests/042                 |    2 +-
 tests/044                 |    2 +-
 24 files changed, 632 insertions(+), 352 deletions(-)
 create mode 100644 include/option.h
 create mode 100644 lib/option.c

-- 
1.7.9.5




More information about the sheepdog mailing list