Skip to content

Commit ea4e978

Browse files
committed
2 parents 9775c44 + b9c6e84 commit ea4e978

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### FSharp.SystemCommandLine ![NuGet version (FSharp.SystemCommandLine)](https://img.shields.io/nuget/v/FSharp.SystemCommandLine.svg?style=flat-square)
1+
### FSharp.SystemCommandLine [![NuGet version (FSharp.SystemCommandLine)](https://img.shields.io/nuget/v/FSharp.SystemCommandLine.svg?style=flat-square)](https://www.nuget.org/packages/FSharp.SystemCommandLine/)
22

33
The purpose of this library is to improve type safety when using the `System.CommandLine` API in F# by utilizing computation expression syntax.
44

@@ -19,32 +19,37 @@ The purpose of this library is to improve type safety when using the `System.Com
1919

2020
```F#
2121
open FSharp.SystemCommandLine
22+
open System.IO
23+
24+
let unzip (zipFile: FileInfo, outputDir: DirectoryInfo) =
25+
// Default to the zip file dir if null
26+
let outputDir =
27+
outputDir
28+
|> Option.ofObj
29+
|> Option.defaultValue zipFile.Directory
2230
23-
let app (words: string array, separator: string) =
24-
System.String.Join(separator, words)
25-
|> printfn "Result: %s"
31+
if zipFile.Exists
32+
then printfn $"Unzipping {zipFile.Name} to {outputDir.FullName}"
33+
else printfn $"File does not exist: {zipFile.FullName}"
2634
2735
[<EntryPoint>]
2836
let main argv =
29-
let words = Input.Option(["--word"; "-w"], (fun () -> Array.empty<string>), "A list of words to be appended")
30-
let separator = Input.Option(["--separator"; "-s"], (fun () -> ","), "A character that will separate the joined words.")
37+
let zipFile = Input.Argument<FileInfo>("The file to unzip")
38+
let outputDir = Input.Option<DirectoryInfo>("-o", (fun () -> null), "The output directory")
3139
3240
rootCommand argv {
33-
description "Appends words together"
34-
inputs (words, separator)
35-
setHandler app
36-
}
41+
description "Unzips a .zip file"
42+
inputs (zipFile, outputDir)
43+
setHandler unzip
44+
}
3745
```
3846

3947
```batch
40-
> TestConsole --word "hello"
41-
Result: hello
42-
43-
> TestConsole --word "hello" -w "world"
44-
Result: hello,world
48+
> unzip.exe "c:\test\stuff.zip"
49+
Result: Unzipping stuff.zip to c:\test
4550
46-
> TestConsole --word "hello" -w "world" -s "***"
47-
Result: hello***world
51+
> unzip.exe "c:\test\stuff.zip" -o "c:\test\output"
52+
Result: Unzipping stuff.zip to c:\test\output
4853
```
4954

5055
Notice that mismatches between the `setHandler` and the `inputs` are caught as a compile time error:

0 commit comments

Comments
 (0)