-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple.sml
More file actions
54 lines (47 loc) · 1.72 KB
/
Copy pathsimple.sml
File metadata and controls
54 lines (47 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(* An example with flags, options and positional arguments. *)
structure SimpleEntrypoint = struct
infix |>
fun x |> f = f x
(* Define the config type that will hold parsed arguments *)
type config = { verbose: bool
, output: string
, count: int
, input: string }
val parser : config Cli.parser =
Cli.app "simple" "1.0.0" "A simple example CLI application"
(fn verbose => fn output => fn count => fn input =>
{ verbose = verbose
, output=output
, count=count
, input=input })
|> Cli.flag { long="verbose"
, short=SOME #"v"
, help="Enable verbose output" }
|> Cli.option { long="output"
, short=SOME #"o"
, help="Output file path"
, placeholder="FILE"
, default="output.txt" }
|> Cli.optionInt { long="count"
, short=SOME #"n"
, help="Number of iterations"
, placeholder="NUM"
, default=1 }
|> Cli.positional { name="input"
, help="Input file to process" }
(* Main function that uses the parsed config *)
fun handler ({verbose, output, count, input}: config) =
let
val _ = if verbose then
print ("Verbose mode enabled\n" ^
"Input: " ^ input ^ "\n" ^
"Output: " ^ output ^ "\n" ^
"Count: " ^ Int.toString count ^ "\n")
else ()
val _ = print ("Processing " ^ input ^ " -> " ^ output ^
" (" ^ Int.toString count ^ " times)\n")
in
()
end
fun run () = Cli.exec handler (Cli.cli parser)
end