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

--help switch throwing exception #366

Closed
melston opened this issue Nov 19, 2018 · 2 comments
Closed

--help switch throwing exception #366

melston opened this issue Nov 19, 2018 · 2 comments

Comments

@melston
Copy link

melston commented Nov 19, 2018

I have a simple F# program that works for all defined command-line options. However, when I run the application with --help I get an exception:

Unhandled Exception: System.Exception: CommandLine.Error[]
   at Program.main(String[] argv) in D:\Projects\Test\FSharp\StoryLib\StoryUpdate\Program.fs:line 46

This line is the last line in the match of the parsing result.

In addition, using the two match options shown in the docs I get a warning about an incomplete pattern match on the expression. It appears that there should be more than

    match args with 
    | :? Parsed<Options> as parsed -> doActions parsed.Value
    | :? NotParsed<Options> as notParsed -> failwith (notParsed.Errors |> string)
    // should there be a third option here?
@WallaceKelly
Copy link
Contributor

WallaceKelly commented Aug 6, 2019

The --help and --version options are treated as NotParsed. But there are extension methods for the errors to detect if the NotParsed result included a --help or --version.

Here is what you need...

match args with 
| :? Parsed<Options> as parsed -> doActions parsed.Value
| :? NotParsed<'a> as notParsed when notParsed.Errors.IsHelp() -> ()
| :? NotParsed<'a> as notParsed when notParsed.Errors.IsVersion() -> ()
| :? NotParsed<Options> as notParsed -> failwith (notParsed.Errors |> string)

@moh-hassan
Copy link
Collaborator

moh-hassan commented Oct 10, 2019

The modified demo will be available in the next Release 2.7

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

3 participants