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

First mandatory special case #58

Closed

Conversation

matthid
Copy link
Member

@matthid matthid commented Jul 2, 2016

Extracted from #57

I added a special case for a "First" parameter if it is "Mandatory" in that case it can be assigned an empty name (which basically allows it to be used as "first" positional argument).

Ideally we would want to have a "Positional parameter" feature. But this is enough for me now (for FAKE, see fsprojects/FAKE#1281).

But now thinking about it in the special case of FAKE fake.exe run build.fsx I could have used an additional parameter in run? Would this work the same:

| [<CliPrefix(CliPrefix.None)>] Run of string * Argu.ParseResult<RunArgs>

?

@eiriktsarpalis
Copy link
Member

I'm not sure I like using AltCommandLine("") for enabling this. Intuitively this translates into expecting that the CLI syntax be of the form fake run '' script.fsx. My recommendation here would be to parse with ignoreUnrecognized = true and then consult the ParseResult.UnrecognizedCliParams property for further processing.

@eiriktsarpalis
Copy link
Member

I've also included a GatherUnrecognized attribute which allows any unrecognized arguments to be accumulated using that particular branch. For instance:

type RunArgs =
    | [<GatherUnrecognized>] Script of string

means that any orphaned token will be parsed to become Script. This could be useful to determine the position of the argument relative to others:

match parser.Parse([|"script.fsx"|]).GetAllResults() with
| Script path :: rest -> // do stuff

@matthid
Copy link
Member Author

matthid commented Jul 5, 2016

what happens if you have multiple GatherUnrecognized? It feels somewhat wrong. Can you escape '-' such that we can specify a file named like an argument (yes it's an edge case but what if tools generate the arguments automatically and need an explicit way of telling that this is a script and not an argument)?

@eiriktsarpalis
Copy link
Member

You mean multiple union cases carrying the GatherUnrecognized attribute? It's not allowed and you'll be getting an error at the parser generation stage. I'm not sure I get the second question.

@matthid
Copy link
Member Author

matthid commented Jul 5, 2016

Ok nice.

The second one is about having a file called '--argument' can I make that work with the new attribute?

@eiriktsarpalis
Copy link
Member

Yes, that has worked with any parameter to an argument. As long as '--foo' is not a parameter in the CLI syntax, it can be parsed as a parameter to any switch that takes string.

@matthid
Copy link
Member Author

matthid commented Jul 5, 2016

Hm maybe that isn't all that important. I think I can live with the suggested solution. My question was about: http://askubuntu.com/questions/482180/unable-to-remove-a-file-which-has-a-name-like-a-command-argument if we have similar things like ' -- '.

Additionally on fake I have this argument called --fsiargs which can be followed by any kind of argument (for the fsi). But I can probably force people to use

fake run scripts.fsx --fsiargs "--other argumen --verbose" --verbose

(That's why I asked for escaping, but now I don't think it's really needed)
Thanks for your patience :)

@matthid matthid closed this Jul 5, 2016
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

Successfully merging this pull request may close these issues.

2 participants