@@ -7,14 +7,8 @@ The purpose of this library is to improve type safety when using the [`System.Co
77
88## Features
99
10- ### Improved type safety
11- * Mismatches between ` inputs ` and ` setHandler ` are caught at compile time
12-
13- ### Helper methods for creating options and arguments
14- * The ` Input.Option ` helper method avoids the need use the ` System.CommandLine.Option ` type directly (which conflicts with the F# ` Option ` type)
15- * The ` FSharp.SystemCommandLine.Aliases ` module contains ` Opt ` and ` Arg ` aliases and can be opened if direct access is needed to the core API.
16-
17- ### Support for F# option type
10+ * Mismatches between ` inputs ` and ` setHandler ` function parameters are caught at compile time
11+ * ` Input.Option ` helper method avoids the need use the ` System.CommandLine.Option ` type directly (which conflicts with the F# ` Option ` type)
1812* ` Input.OptionMaybe ` and ` Input.ArgumentMaybe ` allow you to use F# ` option ` types in your handler function.
1913
2014## Examples
@@ -35,8 +29,8 @@ let unzip (zipFile: FileInfo, outputDirMaybe: DirectoryInfo option) =
3529
3630[<EntryPoint>]
3731let main argv =
38- let zipFile = Input.Argument("The file to unzip")
39- let outputDirMaybe = Input.OptionMaybe(["--output"; "-o"], "The output directory")
32+ let zipFile = Input.Argument<FileInfo> ("The file to unzip")
33+ let outputDirMaybe = Input.OptionMaybe<DirectoryInfo> (["--output"; "-o"], "The output directory")
4034
4135 rootCommand argv {
4236 description "Unzips a .zip file"
@@ -53,6 +47,12 @@ let main argv =
5347 Result: Unzipping stuff.zip to c:\test\output
5448```
5549
50+
51+ _ Notice that mismatches between the ` setHandler ` and the ` inputs ` are caught as a compile time error:_
52+ ![ fs scl demo] ( https://user-images.githubusercontent.com/1030435/164288239-e0ff595d-cdb2-47f8-9381-50c89aedd481.gif )
53+
54+
55+
5656### Simple App that Returns a Status Code
5757
5858You may optionally return a status code from your handler function.
@@ -74,8 +74,8 @@ let unzip (zipFile: FileInfo, outputDirMaybe: DirectoryInfo option) =
7474
7575[<EntryPoint>]
7676let main argv =
77- let zipFile = Input.Argument("The file to unzip")
78- let outputDirMaybe = Input.OptionMaybe(["--output"; "-o"], "The output directory")
77+ let zipFile = Input.Argument<FileInfo> ("The file to unzip")
78+ let outputDirMaybe = Input.OptionMaybe<DirectoryInfo> (["--output"; "-o"], "The output directory")
7979
8080 rootCommand argv {
8181 description "Unzips a .zip file"
@@ -84,9 +84,6 @@ let main argv =
8484 }
8585```
8686
87- Notice that mismatches between the ` setHandler ` and the ` inputs ` are caught as a compile time error:
88- ![ cli safety] ( https://user-images.githubusercontent.com/1030435/158190730-b1ae0bbf-825b-48c4-b267-05a1853de4d9.gif )
89-
9087
9188### App with SubCommands
9289
@@ -101,7 +98,7 @@ let listCmd =
10198 then dir.EnumerateFiles() |> Seq.iter (fun f -> printfn "%s" f.Name)
10299 else printfn $"{dir.FullName} does not exist."
103100
104- let dir = Input.Argument("dir", "The directory to list")
101+ let dir = Input.Argument<DirectoryInfo> ("dir", "The directory to list")
105102
106103 command "list" {
107104 description "lists contents of a directory"
@@ -119,8 +116,8 @@ let deleteCmd =
119116 else
120117 printfn $"{dir.FullName} does not exist."
121118
122- let dir = Input.Argument("dir", "The directory to delete")
123- let recursive = Input.Option("--recursive", false)
119+ let dir = Input.Argument<DirectoryInfo> ("dir", "The directory to delete")
120+ let recursive = Input.Option<bool> ("--recursive", false)
124121
125122 command "delete" {
126123 description "deletes a directory"
@@ -189,9 +186,9 @@ let app (cancel: CancellationToken, words: string array, separator: string) =
189186
190187[<EntryPoint>]
191188let main argv =
192- let cancel = Input.InjectedDependency()
193- let words = Input.Option(["--word"; "-w"], [||], "A list of words to be appended")
194- let separator = Input.Option(["--separator"; "-s"], ", ", "A character that will separate the joined words.")
189+ let cancel = Input.InjectedDependency<CancellationToken> ()
190+ let words = Input.Option<string array> (["--word"; "-w"], [||], "A list of words to be appended")
191+ let separator = Input.Option<string> (["--separator"; "-s"], ", ", "A character that will separate the joined words.")
195192
196193 rootCommand argv {
197194 description "Appends words together"
@@ -225,8 +222,8 @@ let app (svc: WordService) (words: string array, separator: string) =
225222
226223[<EntryPoint>]
227224let main argv =
228- let words = Input.Option(["--word"; "-w"], Array.empty, "A list of words to be appended")
229- let separator = Input.Option(["--separator"; "-s"], ", ", "A character that will separate the joined words.")
225+ let words = Input.Option<string array> (["--word"; "-w"], Array.empty, "A list of words to be appended")
226+ let separator = Input.Option<string> (["--separator"; "-s"], ", ", "A character that will separate the joined words.")
230227
231228 // Initialize app dependencies
232229 let svc = WordService()
0 commit comments