File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,37 @@ let main argv =
5353 Result: Unzipping stuff.zip to c:\test\output
5454```
5555
56+ ### Simple App that Returns a Status Code
57+
58+ You may optionally return a status code from your handler function.
59+
60+ ``` F#
61+ open FSharp.SystemCommandLine
62+ open System.IO
63+
64+ let unzip (zipFile: FileInfo, outputDirMaybe: DirectoryInfo option) =
65+ // Default to the zip file dir if None
66+ let outputDir = outputDirMaybe |> Option.defaultValue zipFile.Directory
67+
68+ if zipFile.Exists then
69+ printfn $"Unzipping {zipFile.Name} to {outputDir.FullName}"
70+ 0 // Program successfully completed.
71+ else
72+ printfn $"File does not exist: {zipFile.FullName}"
73+ 2 // The system cannot find the file specified.
74+
75+ [<EntryPoint>]
76+ let main argv =
77+ let zipFile = Input.Argument("The file to unzip")
78+ let outputDirMaybe = Input.OptionMaybe(["--output"; "-o"], "The output directory")
79+
80+ rootCommand argv {
81+ description "Unzips a .zip file"
82+ inputs (zipFile, outputDirMaybe)
83+ setHandler unzip
84+ }
85+ ```
86+
5687Notice that mismatches between the ` setHandler ` and the ` inputs ` are caught as a compile time error:
5788![ cli safety] ( https://user-images.githubusercontent.com/1030435/158190730-b1ae0bbf-825b-48c4-b267-05a1853de4d9.gif )
5889
You can’t perform that action at this time.
0 commit comments