Re: [PATCH 1/3] ls-tree.c: support `--oid-only` option for "git-ls-tree"
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Nov 18, 2021, 11:00 UTC
- Message-ID
- <211118.86czmx67yi.gmgdl@evledraar.gmail.com>
- In-Reply-To
- <20211118092803.78395-1-dyroneteng@gmail.com>
On Thu, Nov 18 2021, Teng Long wrote:
Show 19 quoted lines
>> If you make these an OPT_CMDMODE you get this behavior for free. See >> e.g. my >> https://lore.kernel.org/git/patch-v2-06.10-d945fc94774-20211112T221506Z-avarab@gmail.com/ > > Thank you very much for providing this input. > > So I try to read this patch your mentioned and try to repeat the idea in my understanding. > > First, OPT_CMDMODE() can be used for: > > 1. Easy for checking the combined command options, such as "mutually exclusive" conditions. > > 2. Die and output the error message consistently when the incompatible options are found. > > 3. Brings better extensibilites, no need to change a lot of if/elses. > > Then, you suggest to consider about to use OPT_CMDMODE instead of the current implementations. > > Did I understand your suggestion right and comprehensive?
Yes, all of that is correct.
It's a way of defining N options, --foo, --bar, --baz, where combining any of them is an error.
We usually use it for a "command mode" (hence the name), but it can be used when the command has flags that are mutually exclusive.
I think (but am not sure, and didn't check) that you can even use it for --foo AND --bar that are exclusive, and --other --flags that are also mutually exclusive (but could be combined with one of --foo or --bar), you just need to provide another variable for it to set.
But I haven't tested that or used it like that, maybe it doesn't work for some reason I'm forgetting...