git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/2] Parsing a subcommand using parse-options

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Dec 8, 2011, 12:07 UTC
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
Next: Ramkumar Ramachandra
Message 1 of 4 in “Parsing a subcommand using parse-options”
  1. 0/2 Parsing a subcommand using parse-optionsRamkumar Ramachandra, Dec 8, 2011
  2. 1/2 parse-options: introduce OPT_SUBCOMMANDRamkumar Ramachandra, Dec 8, 2011
  3. 2/2 bundle: rewrite builtin to use parse-optionsRamkumar Ramachandra, Dec 8, 2011
  4. Junio C HamanoDec 8, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.