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

feat: correct way to specify a list that's allowed to be empty? #91

Open
Gastove opened this issue Sep 14, 2017 · 3 comments
Open

feat: correct way to specify a list that's allowed to be empty? #91

Gastove opened this issue Sep 14, 2017 · 3 comments

Comments

@Gastove
Copy link

Gastove commented Sep 14, 2017

This isn't particularly an issue so much as point of confusion on my part. I need, effectively, a optional list. Specifying an argument as having type string list option throws an error, and the docs do specify Note that arguments that use optional or list must have precisely one parameter -- so, alright. But if I specify that a parameter has type string list, it's now required. What I'm looking for is, "if the user doesn't specify a list, the list will be empty list", say. Perhaps the correct approach is a default value in the App.config? Would be very curious if there's a "recommended" way to do this.

@eiriktsarpalis
Copy link
Member

You can use the GetResults method which returns a list of all arguments. So if you pass the args

-f 1 -f 2 -f 3

Then GetResults <@ f @> would give back [1 ; 2 ; 3]. Assuming -f works with lists, then you'd be given a list of lists, so concatenating that result should be sufficient to get the desired result.

@odytrice
Copy link

odytrice commented May 17, 2019

I ran into a similar issue. let's say I want something like

type Arguments =
    | Numbers of numbers : int list
    interface IArgParserTemplate with
        member s.Usage =
            match s with
            | Numbers _ -> "Optional list of numbers to process (e.g. 10042 10043)"

So that I could invoke the app in two ways

app.exe --numbers 10042 10043 or app.exe

The former behaves as expected. However, the later throws Unhandled Exception: Argu.ArguParseException: ERROR: missing argument '--numbers'.

Whereas what one would expect to happen is that the parse would pass with the following behaviour

arguments.GetResult(<@ Arguments.Numbers @>) //Returns []

Currently, the workaround is do something like app.exe --numbers

If you agree with the proposed behavior, I should be able to implement it and send a PR

@eiriktsarpalis
Copy link
Member

Sounds reasonable. It's been ages since I wrote that code, but I have a slight hunch that the restriction might have been motivated by technical reasons.

@bartelink bartelink changed the title Question: correct way to specify a list that's allowed to be empty? feat: correct way to specify a list that's allowed to be empty? Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants