From: Ramkumar Ramachandra Date: Thu, 08 Dec 2011 12:07:06 GMT Subject: [PATCH 0/2] Parsing a subcommand using parse-options Message-ID: <1323346028-9201-1-git-send-email-artagnon@gmail.com> Hi, It's been itching me for some time now: I want parse-options to be able to parse a "subcommand". It all started when I noticed how ugly my implementation of '--continue' and '--quit' in git-revert were: using an OPT_BOOLEAN to parse the option into separate integer variables, and then using if-else constructs to turn that into an enum. Yuck! Also, wouldn't we all love something like this in the future? git stash show ^^ -- The subcommand "show" to the git-stash builtin Ofcourse, git-stash.sh is just a shell script, and the full motivation doesn't arise until someone decides to turn it into a C builtin. So, I went hunting for a C builtin that used subcommands and found something relatively obscure: git-bundle. It does option-parsing by hand; changing it to use parse-options is the perfect opportunity to implement this subcommand feature! Thoughts? -- Ram Ramkumar Ramachandra (2): parse-options: introduce OPT_SUBCOMMAND bundle: rewrite builtin to use parse-options builtin/bundle.c | 111 ++++++++++++++++++++++++++++++---------------- parse-options.c | 5 +- parse-options.h | 3 + t/t0040-parse-options.sh | 31 +++++++++++++ test-parse-options.c | 4 ++ 5 files changed, 114 insertions(+), 40 deletions(-) -- 1.7.7.3