Skip to content

Commit 31bc75f

Browse files
authored
Updated README.md with 0.4.0-alpha changes
1 parent ea4e978 commit 31bc75f

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ The purpose of this library is to improve type safety when using the `System.Com
1111

1212
### Provide helper methods via the `Input` class for creating `Option` and `Argument` types
1313
* Avoids initializing the `Option` type directly (which conflicts with the F# `Option` type)
14-
* Eliminates the need to manually cast inputs to the `IValueDescriptor` interface
14+
* `FSharp.SystemCommandLine.Aliases` module contains `Opt` and `Arg` aliases (as an alternative to using the `Input` helper class)
15+
16+
### Support for F# `Option` type
17+
* `Input.OptionMaybe` and `Input.ArgumentMaybe` allow you to use F# `option` types in your handler function.
1518

1619
## Examples
1720

@@ -21,25 +24,22 @@ The purpose of this library is to improve type safety when using the `System.Com
2124
open FSharp.SystemCommandLine
2225
open System.IO
2326
24-
let unzip (zipFile: FileInfo, outputDir: DirectoryInfo) =
27+
let unzip (zipFile: FileInfo, outputDirMaybe: DirectoryInfo option) =
2528
// Default to the zip file dir if null
26-
let outputDir =
27-
outputDir
28-
|> Option.ofObj
29-
|> Option.defaultValue zipFile.Directory
29+
let outputDir = outputDirMaybe |> Option.defaultValue zipFile.Directory
3030
3131
if zipFile.Exists
3232
then printfn $"Unzipping {zipFile.Name} to {outputDir.FullName}"
3333
else printfn $"File does not exist: {zipFile.FullName}"
3434
3535
[<EntryPoint>]
3636
let main argv =
37-
let zipFile = Input.Argument<FileInfo>("The file to unzip")
38-
let outputDir = Input.Option<DirectoryInfo>("-o", (fun () -> null), "The output directory")
37+
let zipFile = Input.Argument("The file to unzip")
38+
let outputDirMaybe = Input.OptionMaybe(["--output"; "-o"], "The output directory")
3939
4040
rootCommand argv {
4141
description "Unzips a .zip file"
42-
inputs (zipFile, outputDir)
42+
inputs (zipFile, outputDirMaybe)
4343
setHandler unzip
4444
}
4545
```
@@ -78,8 +78,8 @@ let app (svc: WordService) (words: string array, separator: string) =
7878
7979
[<EntryPoint>]
8080
let main argv =
81-
let words = Input.Option(["--word"; "-w"], (fun () -> Array.empty<string>), "A list of words to be appended")
82-
let separator = Input.Option(["--separator"; "-s"], (fun () -> ", "), "A character that will separate the joined words.")
81+
let words = Input.Option(["--word"; "-w"], Array.empty, "A list of words to be appended")
82+
let separator = Input.Option(["--separator"; "-s"], ", ", "A character that will separate the joined words.")
8383
8484
// Initialize app dependencies
8585
let svc = WordService()
@@ -88,7 +88,8 @@ let main argv =
8888
description "Appends words together"
8989
inputs (words, separator)
9090
usePipeline (fun builder ->
91-
builder.UseTypoCorrections(3) // Override pipeline
91+
CommandLineBuilder() // Pipeline is initialized with .UseDefaults() by default,
92+
.UseTypoCorrections(3) // but you can override it here if needed.
9293
)
9394
setHandler (app svc) // Partially apply app dependencies
9495
}
@@ -108,7 +109,7 @@ let listCmd =
108109
then dir.EnumerateFiles() |> Seq.iter (fun f -> printfn "%s" f.Name)
109110
else printfn $"{dir.FullName} does not exist."
110111
111-
let dir = Input.Argument(fun () -> DirectoryInfo("c:\fake dir"))
112+
let dir = Input.Argument("dir", DirectoryInfo(@"c:\fake dir"))
112113
113114
command "list" {
114115
description "lists contents of a directory"
@@ -125,8 +126,8 @@ let deleteCmd =
125126
else
126127
printfn $"{dir.FullName} does not exist."
127128
128-
let dir = Input.Argument(fun () -> DirectoryInfo("c:\fake dir"))
129-
let recursive = Input.Option("--recursive", getDefaultValue = (fun () -> false))
129+
let dir = Input.Argument("dir", DirectoryInfo(@"c:\fake dir")
130+
let recursive = Input.Option("--recursive", false)
130131
131132
command "delete" {
132133
description "deletes a directory"

0 commit comments

Comments
 (0)