fsprojects / Argu

A declarative CLI argument parser for F#
https://fsprojects.github.io/Argu
MIT License
457 stars 74 forks source link

feat: Add GetResult(expr, defThunk) #187

Closed bartelink closed 10 months ago

bartelink commented 11 months ago

Useful to defer computation work (or raising of an exception in the course of that) to look up a fallback where a parameter is missing

bartelink commented 11 months ago

Workaround is carting around:

type Argu.ParseResults<'T when 'T :> Argu.IArgParserTemplate> with
    member x.GetResult([<ReflectedDefinition>] e: Quotations.Expr<'Fields -> 'T>, f: unit -> 'Fields) = x.TryGetResult(e) |> Option.defaultWith f
nojaf commented 10 months ago

Could you add a release note and a new version for this? We can have another release with this.

bartelink commented 10 months ago

Sure, 6.1.3, or another number?

nojaf commented 10 months ago

Not entirely sure, 6.1.3 sounds right to me. Although I don't have the greatest insight into this specific fix.

bartelink commented 10 months ago

On reflection, I think the correct implementation may be a bit more involved...

Give me a while before we merge it...

bartelink commented 10 months ago

@nojaf OK, happier with this If the truth be told, I'm sill looking for a fully integrated way of having a <MandatoryOrFromEnvVar "name"> mechanism as I'm rappling for in https://github.com/fsprojects/Argu/issues/143 though!

nojaf commented 10 months ago

I'm going to try another publish with this fix.

bartelink commented 10 months ago

Looks great, nice work (though I see my summary docs are lacking...) https://fsprojects.github.io/Argu/reference/argu-parseresults-1.html#GetResult