Argu icon indicating copy to clipboard operation
Argu copied to clipboard

IsUsageRequested is not true for missing mandatory subcommand args

Open haf opened this issue 7 years ago • 4 comments

Description

E.g.

type RMode = R1 | R2
type RouterArgs =   | [<Mandatory>] Listener of routerMode:RMode
type Args = | [<CliPrefix(CliPrefix.None)>] Router of args:ParseResults<RouterArgs>
let parser = ArgumentParser.Create<Args>(programName = "rutta.exe", helpTextMessage = "repro")
let parsed = parser.Parse([| "Router" |], ignoreUnrecognized=true, raiseOnUsage=false)
parsed.IsUsageRequested  // => false, but should be true, because Router is missing a Listener.

haf avatar Apr 09 '18 12:04 haf

https://github.com/logary/logary/pull/387/commits/57c1374afee16f8119f8430c9594855c48473cc6

Inside dir src/services/Logary.Services.Rutta (se commit message)

screenshot 2019-02-16 at 23 03 13

haf avatar Feb 16 '19 22:02 haf

Has this been fixed with any of the releases in the last two years?

haf avatar Jul 12 '20 12:07 haf

Probably not, at least it hasn't been addressed intentionally.

eiriktsarpalis avatar Jul 13 '20 12:07 eiriktsarpalis

Ok, no worries, there's a workaround available. I saw the docs had been updated about subcommand parsing, that's why I asked. Thanks for the reply.

haf avatar Jul 13 '20 12:07 haf

There's a good release pipeline and active maintainers if you (or anyone) wanted to take a run at it now...

bartelink avatar Dec 14 '23 09:12 bartelink

IsUsageRequested is currently only true if help is requested, not in the event of an error. So the case reported seems to be a change in behaviour. Nevertheless, the mandatory field will raise an exception with the parse arguments used in the initial message with #221 . This may meet haf's need.

fpellet avatar Jan 20 '24 09:01 fpellet

Atm IsUsageRequested seems do exactly what it purports to - convey whether the --help option (or configured custom equivalents) has been explicitly specified.

I'm not averse to an alteration/clarification to how this should work overall, but in general I'd expect there to be APIs to verify missing arguments either via a property or ArguParseException, with the caller mapping that to printing of help as desired (i.e. while --help should definitely trigger a help message, I can imagine people wanting to be selective about whether to do that in the case of arguments being missing; having the 'help requested' and 'help might make sense because there's missing arguments' aspects be separated seems to be clearest approach, but I may well be missing a very obvious and clean answer).

Closing for now - if anyone wants to propose a set of tests and API changes to represent the overall semantics, the build pipeline is now in a good place to get it released the minute we have a clear proposal as to how it should work.

bartelink avatar Jan 22 '24 01:01 bartelink