-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-like.sml
More file actions
51 lines (47 loc) · 1.82 KB
/
Copy pathgit-like.sml
File metadata and controls
51 lines (47 loc) · 1.82 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 a more complex CLI with multiple optional arguments. *)
structure GitLikeEntrypoint = struct
infix |>
fun x |> f = f x
(* Config type for a hypothetical git-add command *)
type config = { force: bool
, dryRun: bool
, verbose: bool
, interactive: bool
, files: string list }
val parser : config Cli.parser =
Cli.app "git-add" "1.0.0" "Add file contents to the index"
(fn force => fn dryRun => fn verbose => fn interactive => fn files =>
{ force = force
, dryRun = dryRun
, verbose = verbose
, interactive = interactive
, files = files })
|> Cli.flag { long = "force"
, short = SOME #"f"
, help = "Allow adding otherwise ignored files" }
|> Cli.flag { long = "dry-run"
, short = SOME #"n"
, help = "Don't actually add files, just show what would happen" }
|> Cli.flag { long = "verbose"
, short = SOME #"v"
, help = "Be verbose" }
|> Cli.flag { long = "interactive"
, short = SOME #"i"
, help = "Interactive picking" }
|> Cli.positionalList { name = "files"
, help = "Files to add" }
fun handler ({force, dryRun, verbose, interactive, files}: config) =
let
val prefix = if dryRun then "[dry-run] " else ""
val _ = if verbose then
print ("Force: " ^ Bool.toString force ^ "\n" ^
"Dry run: " ^ Bool.toString dryRun ^ "\n" ^
"Interactive: " ^ Bool.toString interactive ^ "\n")
else ()
val _ = List.app (fn f =>
print (prefix ^ "add '" ^ f ^ "'\n")) files
in
()
end
fun run () = Cli.exec handler (Cli.cli parser)
end