Skip to content

Releases: JordanMarr/FSharp.SystemCommandLine

Support for command aliases

08 Apr 15:19
Compare
Choose a tag to compare

Changes in v0.17.0-beta4

  • New addAlias and addAliases operations to add command aliases. (thanks to @AngelMunoz! πŸš€)
  • Deprecated add overloads and renamed to addInput and addInputs for clarity and consistency

Support for netstandard, `add` overload

01 Apr 19:08
Compare
Choose a tag to compare

New in v0.16.0-beta4

  • Support added for netstandard2.0
  • New add overload that accepts multiple inputs (for when you have a lot!)

Thanks to @jbtule for contributing this in PR #14!

Input helpers

25 Feb 20:25
Compare
Choose a tag to compare

This release adds a few new Input methods to make it more convenient to modify the underlying System.CommandLine properties for Option and Argument inputs.

  • New Input.Option overloads that take a name/alias and a configure function that allows you to manually set properties on the S.CL Option<'T>.
  • New Input.OptionMaybe overloads that take a name/alias and a configure function that allows you to manually set properties on the S.CL Option<'T option>.
  • New Input.Argument overloads that take a name/alias and a configure function that allows you to manually set properties on the S.CL Argument<'T>.

Please see updated docs here:
https://github.com/JordanMarr/FSharp.SystemCommandLine#setting-input-properties-manually

Also, two new alias methods (for easier discoverability) for converting existing SCL inputs:

  • Input.OfOption - An alias for HandlerInput.OfOption
  • Input.OfArgument - An alias for HandlerInput.OfArgument

Handling of greater than 8 inputs

14 Jan 22:12
Compare
Choose a tag to compare

This release provides a convenient way to handle commands that require more than 8 inputs via the new add custom operation on the rootCommand and command builders.

Additional info

Currently, a command handler function is limited to accept a tuple with no more than eight inputs.
If you need more than eight inputs, you can now pass in the InvocationContext to your handler, which will allow you manually get as many input values as you like (assuming they have been registered via the rootCommand or command builder's add operation:

module Program

open FSharp.SystemCommandLine

module Parameters = 
    let words = Input.Option<string[]>(["--word"; "-w"], Array.empty, "A list of words to be appended")
    let separator = Input.OptionMaybe<string>(["--separator"; "-s"], "A character that will separate the joined words.")

let app (ctx: System.CommandLine.Invocation.InvocationContext) =
    // Manually parse as many parameters as you need
    let words = Parameters.words.GetValue ctx
    let separator = Parameters.separator.GetValue ctx

    // Do work
    let separator = separator |> Option.defaultValue ", "
    System.String.Join(separator, words) |> printfn "Result: %s"
    0
    
[<EntryPoint>]
let main argv = 
    let ctx = Input.Context()

    rootCommand argv {
        description "Appends words together"
        inputs ctx
        setHandler app
        add Parameters.words
        add Parameters.separator
    }

Caveats

This manual binding mechanism is less type safe because the compiler has no way to determine if you have manually added all input parameters to the command; so if you forget to add one that is used, it will result in a runtime error.

(For this reason, you should try to limit your commands to 8 parameters when possible, by factoring your app into separate commands.)

beta4 changes

07 Jun 19:49
Compare
Choose a tag to compare

v0.13.0-beta4 adapts to the System.CommandLine beta4 changes.
The API stays mostly the same with the following changes:

  • πŸ’₯ Removed Input.InjectedDependency<'T>() (this allowed you to pass in S.CL injected system dependencies like InvocationContext, CancellationToken, IConsole, etc.

  • ⭐ Added Input.Context() for passing InvocationContext to handler function.
    This replaces Input.InjectedDependency<'T>() because InvocationContext can be used to get a CancellationToken, IConsole, etc.

  • Handler functions now support 8 input bindings instead of 16 (following changes to S.CL).
    (If you need more than 8 input bindings, you can pass the InvocationContext to your handler function using the new Input.Context() method which will allow you to manually get as many parsed values as you want.)

The readme has been updated with an example of passing the InvocationContext:
https://github.com/JordanMarr/FSharp.SystemCommandLine#passing-the-invocationcontext

NEW: rootCommandParser CE

29 Apr 13:31
Compare
Choose a tag to compare

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

25 Apr 02:04
Compare
Choose a tag to compare
  • Fixed an issue where Input.OptionMaybe<bool>("--flag") would not translate --flag to Some true unless it had a boolean argument value (--flag true).

Fixed ArgumentMaybe

24 Apr 03:54
Compare
Choose a tag to compare
  • Fixed a bug with Input.ArgumentMaybe.
  • Added support for Uri for the makeshift Maybe parser. (parsing for OptionMaybe and ArgumentMaybe helpers is currently being done within FSharp.SystemCommandLine. This is because the parsing code in System.CommandLine is currently internal and therefore unusable for reuse when creating custom types).

NEW: OptionRequired

17 Apr 15:11
Compare
Choose a tag to compare

Added Input.OptionRequired overloads.

NEW: `addCommands` and `addCommand`

12 Apr 15:39
Compare
Choose a tag to compare

Deprecated setCommand in favor of addCommand or addCommands.