Releases: JordanMarr/FSharp.SystemCommandLine
NEW: rootCommandParser CE
Added a rootCommandParser to provide the opportunity to manually parse and invoke a root command (since the rootCommand is auto-executing).
open FSharp.SystemCommandLine
open System.CommandLine.Parsing
let app (words: string array, separator: string option) =
let separator = separator |> Option.defaultValue ", "
System.String.Join(separator, words) |> printfn "Result: %s"
0
[<EntryPoint>]
let main argv =
let words = Input.Option(["--word"; "-w"], Array.empty, "A list of words to be appended")
let separator = Input.OptionMaybe(["--separator"; "-s"], "A character that will separate the joined words.")
let parser =
rootCommandParser {
description "Appends words together"
inputs (words, separator)
setHandler app
}
parser.Parse(argv).Invoke()Fixed OptionMaybe bool with no arguments
- Fixed an issue where
Input.OptionMaybe<bool>("--flag")would not translate--flagtoSome trueunless it had a boolean argument value (--flag true).
Fixed ArgumentMaybe
- Fixed a bug with
Input.ArgumentMaybe. - Added support for
Urifor the makeshift Maybe parser. (parsing forOptionMaybeandArgumentMaybehelpers is currently being done withinFSharp.SystemCommandLine. This is because the parsing code inSystem.CommandLineis currently internal and therefore unusable for reuse when creating custom types).
NEW: OptionRequired
Added Input.OptionRequired overloads.
NEW: `addCommands` and `addCommand`
Deprecated setCommand in favor of addCommand or addCommands.
Support for returning int code from non-task handlers
This release adds built-in support for return an int status code from synchronous handler functions.
S.CL already supports return Task<int> from asynchronous handlers, but return a status code from sync handlers requires injecting InvocationContext into your sync handler and setting the ExitCode property.
While v0.6.0 added support for injecting dependencies, this release aims to take this use case easier by injecting InvocationContext behind-the-scenes on the behalf of the user (at the expense of using one of the handler's 16 parameter slots).
See this example of returning a status code.
Dependency Injection
This release adds support for dependency injected inputs in your handler functions via the Input.InjectedDependency helper method.
See Async App with an Injected CancellationToken example.
Support for returning int code from Task handlers
This release adds the ability to return a Task<int> status code from your asynchronous command handler functions.
Support for F# Option Type
v0.4.0-alpha
New Features
- Add support for F# option types via
Input.OptionMaybeandInput.ArgumentMaybe(See README.md for updated examples) - Added
FSharp.SystemCommandLine.Aliasesmodule withOpt<'T>andArg<'T>convenience aliases forSystem.CommandLine.Option<'T>andSystem.CommandLine.Argument<'T>. (This should only be needed if you need to fall back to the core API in the case that a feature is missing from theInput.OptionandInput.Argumenthelpers.)
Breaking Changes
- Reworked all
Input.OptionandInput.Argumentoverloads that took agetDefaultValueanonymous function to use adefaultValueinstead. This makes the most common use case much cleaner for F# by removing the anonymous function syntax.
Before:
let words = Input.Option(["--word"; "-w"], (fun () -> Array.empty), "A list of words to be appended")After:
let words = Input.Option(["--word"; "-w"], Array.empty, "A list of words to be appended")