Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change short options to "optionally accept" 1 param by default, except the last one, which should take none...? #43

Open
7 tasks
xparq opened this issue Nov 1, 2023 · 0 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@xparq
Copy link
Owner

xparq commented Nov 1, 2023

  • Also, "optionally accept" 1 param means "take the next param, except if it looks like another named arg" (like greedy consuming of params, but for 1)!

All would be still configurable, of course, incl. having the current behavior exactly. It's just about more intuitive defaults.
The current default of short options being just nullary predicates* has bitten me at OON, with -C cfgfile "not working"...

The new defaults may sound like a convoluted, arbitrary rule, but may be more intuitive actually, as positional args. are
rarely intermixed with named ones in practice (they tend to come after the "switches")!

  • One big problem, though: during the parsing loop there's no way to know in advance that the "last one" is actually the last one, so that might mean reparsing that whole chunk! Which, well, could be reduced to

    • a) flag every "non-rule-driven" (i.e. implicit-arity) short option as "tentatively last" (for later massaging)
    • b remove that flag if another named arg comes (either explicit (rule-driven), or implicit (default))
    • c) when finished, if there's a "tentatively last" named option, take its param away (assert that it has one, or there's no positional args at all!), and add it to the positionals
  • And another, possibly even a show-stopper for this change: this would prevent intermixing named and unnamed options at all, without requiring to define rules for each (named) option! :-o
    But... This may just be how command-line args should actually work? I can't come up right away with a practical example, where unnamed options are not in fact just params of some named arg. But scripts that need to tuck positional args at the end of half-assembled command strings, without knowing what came before, may suffer!

    • Implement it anyway, and take it for a long test ride!

* Wait, no... :-o This is what the general test case says:

RUN args-test.exe --one 99 2 3 4 -i a b c -h --long=1

EXPECT "\
-------- NAMED:
h
i = a, b, c
...

WTF is going on then? :-o

Arrrghs!... :) The test exe has non-default rules, and has -i defined as greedy!

@xparq xparq added enhancement New feature or request question Further information is requested labels Nov 1, 2023
@xparq xparq changed the title Change short options to accept 1 param by default, except the last one, which should take none Change short options to "optionally accept" 1 param by default, except the last one, which should take none Nov 1, 2023
@xparq xparq changed the title Change short options to "optionally accept" 1 param by default, except the last one, which should take none Change short options to "optionally accept" 1 param by default, except the last one, which should take none...? Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant