Skip to content
A framework for building command line application in F#
F# Other
  1. F# 99.3%
  2. Other 0.7%
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
src
.gitattributes
.gitignore
FSharp.CommandLine.sln
LICENSE.txt
README.md
RELEASE_NOTES.md
build.fsx
build.fsx.lock
fake.cmd
fake.sh
nuget.config
test.fsx

README.md

FSharp.CommandLine

The FSharp.CommandLine library can be installed from NuGet

  PM> Install-Package FSharp.CommandLine

FSharp.CommandLine is a monadic commandline application framework that automatically generates both help texts and shell suggestions.

This library also contains type-safe scanf and type-safe commandline option parser.

Example

open System
open FSharp.CommandLine

let fileOption =
  commandOption {
    names ["f"; "file"]
    description "Name of a file to use (Default index: 0)"
    takes (format("%s:%i").withNames ["filename"; "index"])
    takes (format("%s").map (fun filename -> (filename, 0)))
    suggests (fun _ -> [CommandSuggestion.Files None])
  }

type Verbosity = Quiet | Normal | Full | Custom of int

let verbosityOption =
  commandOption {
    names ["v"; "verbosity"]
    description "Display this amount of information in the log."
    takes (regex @"q(uiet)?$" |> asConst Quiet)
    takes (regex @"n(ormal)?$" |> asConst Quiet)
    takes (regex @"f(ull)?$" |> asConst Full)
    takes (format("custom:%i").map (fun level -> Custom level))
    takes (format("c:%i").map (fun level -> Custom level))
  }

let mainCommand () =
  command {
    name "main"
    description "The main command."
    opt files in fileOption |> CommandOption.zeroOrMore
    opt verbosity in verbosityOption |> CommandOption.zeroOrExactlyOne 
                                     |> CommandOption.whenMissingUse Normal
    do printfn "%A, %A" files verbosity
    return 0
  }

[<EntryPoint>]
let main argv =
  mainCommand() |> Command.runAsEntryPoint argv

License

Apache 2. See LICENSE.txt for details.

You can’t perform that action at this time.