You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No dependencies! The standard CommandLineParser package has no dependencies. If you want FSharp support, you should reference the CommandLineParser.FSharp package.
Getting Started will show you how to get started with step-by-step instructions
As you can see the options.offset record member was defined as option<int64> since the library has full support for option<'a> (full CLR name type name Microsoft.FSharp.Core.FSharpOption<T>).
Note:
The properties of the Options class should be public. Internal properties are not updated by the Parser.
Help Screen
One of strengths of this library lies in the ability to automatically generate a help screen for the end user. See the Generating Help and Usage information page for more information.
[Usage] Attribute
The Usage attribute is a new 2.0.x feature that allows you to add a properly formatted USAGE: section to your help screen. One or more usage examples can be defined, by providing a static IEnumerable<Example> property annotated with the [Usage] attribute.
usingCommandLine.Text;classOptions{[Option("filename",Required=false,HelpText="Input filename.")]publicstringfilename{get;set;}[Usage(ApplicationAlias="yourapp")]publicstaticIEnumerable<Example>Examples{get{returnnewList<Example>(){newExample("Convert file to a trendy format",newOptions{filename="file.bin"})};}}}
Will produce the following help text:
yourapp 2.0.201-alpha
Copyright (c) 2005 - 2015 Giacomo Stelluti Scala
USAGE:
Convert file to a trendy format:
yourapp --filename file.bin
--filename Input filename.
--help Display this help screen.
--version Display version information.
More than one usage can be defined. It is also possible to format the displayed usage by providing a list of UnParserSettings.
classOptions{// Normal options here.[Usage(ApplicationAlias="yourapp")]publicstaticIEnumerable<Example>Examples{get{yieldreturnnewExample("Normal scenario",newOptions{InputFile="file.bin",OutputFile="out.bin"});yieldreturnnewExample("Logging warnings",UnParserSettings.WithGroupSwitchesOnly(),newOptions{InputFile="file.bin",LogWarning=true});yieldreturnnewExample("Logging errors",new[]{UnParserSettings.WithGroupSwitchesOnly(),UnParserSettings.WithUseEqualTokenOnly()},newOptions{InputFile="file.bin",LogError=true});}}}
When working with formatting styles, the important thing to know is that UnParserSettings is exactly the same type accepted by Parser.FormatCommandLine<T>(T options, Action<UnParserSettings>); since this API is the same used internally to generate part of the example command line.
UnParserSettings.WithGroupSwitchesOnly() and UnParserSettings.WithUseEqualTokenOnly() are just factory methods to simplify the creation of an instance with the property in the name set to true.
If you're an experienced command line user, you're wondering how AutoBuild() will handle this data when you define AssemblyUsage attribute. It will follows the rules above:
Prints header (SentenceBuilder.UsageHadingText) if you've used Usage or AssemblyUsage attribute and such header isn't an empty string (default USAGE:).
Prints content provided by AssemblyUsage if defined.
Prints content provided by Usage if defined.
The above output is taken from a unit test.
yourapp 2.0.201-alpha
Copyright (c) 2005 - 2015 Giacomo Stelluti Scala
ERROR(S):
Option 'badoption' is unknown.
USAGE:
Cloning quietly:
git clone --quiet https://github.com/gsscoder/railwaysharp
Cloning without hard links:
git clone --no-hardlinks https://github.com/gsscoder/csharpx
--no-hardlinks Optimize the cloning process from a repository on a local filesystem by copying files.
-q, --quiet Suppress summary message.
--help Display this help screen.
--version Display version information.
URLS (pos. 0) A list of url(s) to clone.
If you build HelpText instance by your own, you can rely on three methods to gather Usage attribute data: