Re: [PATCH] Add a simple option parser.
From: Pierre Habouzit <hidden>
Date: 2016-06-15 22:43:38
On Thu, Oct 04, 2007 at 02:57:58PM +0000, Kristian Høgsberg wrote:
On Thu, 2007-10-04 at 01:11 +0200, Pierre Habouzit wrote:quoted
On Wed, Oct 03, 2007 at 09:45:01PM +0000, Kristian Høgsberg wrote:quoted
The option parser takes argc, argv, an array of struct option and a usage string. Each of the struct option elements in the array describes a valid option, its type and a pointer to the location where the value is written. The entry point is parse_options(), which scans through the given argv, and matches each option there against the list of valid options. During the scan, argv is rewritten to only contain the non-option command line arguments and the number of these is returned.if we are going in that direction (and I believe it's a good one), we should be sure that the model fits with other commands as well. And as I said on IRC, I believe the most "horrible" (as in complex) option parser in git is the one from git-grep. A migration of git-grep on that API should be tried first. If this works well enough, I believe that the rest of the git commands will be migrated easily enough. (with maybe small addition to parse-option.[hc] but the hardcore things should have been met with git-grep already I think).I'm not sure - we can go with the current proposal and add new options types and probably the callback option type I suggested as we go. I don't want to block builtin-commit on figuring out what the perfect option parser should look like and what I sent out earlier work for commit. I think the way you handled the strbuf rewrites worked pretty well; extending and rewriting the API as you put it to use in more and more places. We can do the same thing with parse_options().
Of course we can do that, or junio said that some people talked about popt some time ago. I understand that you don't want to block the git-commit work, but doing things right from the beginning is often a big win on the long term. I don't know popt, and I don't know if it has sufficient expressivity. For sure I don't like getopt_long APIs at all, so if popt is as cumbersome, rolling our own based on the current parse_options you propose is probably a good choice. -- ·O· Pierre Habouzit ··O madcoder@debian.org OOO http://www.madism.org
Attachments
- (unnamed) [application/pgp-signature] 189 bytes