Expand arg cli example

This commit is contained in:
Ayaz Hafiz 2022-09-13 13:02:46 -04:00
parent 0672a591b6
commit 487ecee143
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58

View File

@ -6,11 +6,33 @@ app "args"
main : List Str -> Task.Task {} [] [Write [Stdout]]
main = \args ->
parser =
Arg.succeed (\mode -> mode)
|> Arg.apply (Arg.str { long: "mode", help: Some "the mode flag" })
Arg.choice [
Arg.subCommand
"exclaim"
(Arg.succeed (\s -> Exclaim s)
|> Arg.withParser (Arg.str {
long: "string",
short: Some "s",
help: Some "the string to exclaim",
})),
Arg.subCommand
"greet"
(Arg.succeed (\name -> \greeting -> Greet { name, greeting })
|> Arg.withParser (Arg.str {
long: "name",
help: Some "the name of the individual to greet",
})
|> Arg.withParser (Arg.str {
long: "greeting",
short: Some "g",
help: Some "the greeting to use",
}))
]
when Arg.parseFormatted parser args is
Ok mode ->
Stdout.line "You chose mode \(mode)"
Ok (Exclaim s) ->
Stdout.line "\(s)!"
Ok (Greet {name, greeting}) ->
Stdout.line "\(greeting), \(name)"
Err helpMenu ->
Stdout.line helpMenu