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

Can ArgParseResults be constructed? #35

Closed
ctaggart opened this issue May 27, 2015 · 5 comments
Closed

Can ArgParseResults be constructed? #35

ctaggart opened this issue May 27, 2015 · 5 comments

Comments

@ctaggart
Copy link
Contributor

For fsprojects/Paket#839, I would like to call these functions by constructing and passing in the ArgParseResults. Is this possible?

let args = [ RestoreArgs.Force ; RestoreArgs.References_Files "abc.txt" ]
Program.restore (ArgParseResults<RestoreArgs>(args))
@ctaggart
Copy link
Contributor Author

My use case is I want a way to get this working:

image

@eiriktsarpalis
Copy link
Member

You can sort of achieve this by doing the following:

type UnionArgParser<'Args when 'Args :> IArgParserTemplate> with
    member parser.CreateParseResultsOfList(inputs : 'Args list) : ParseResults<'Args> =
        let cliParams = parser.PrintCommandLine inputs // unparse inputs to cli form
        parser.ParseCommandLine(inputs = cliParams, ignoreMissing = true)

This will unparse the inputs to string and then re-parse them to form the required ParseResults object. Note that this will not work with arguments that carry the NoCommandLineAttribute.

@ctaggart
Copy link
Contributor Author

Awesome! Thanks.

@ctaggart
Copy link
Contributor Author

@eiriktsarpalis Any chance we can get something like parser.CreateParseResultsOfList baked in?

@eiriktsarpalis
Copy link
Member

@ctaggart I'm willing to accept PRs that implement this :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants