mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
Expand arg cli example
This commit is contained in:
parent
0672a591b6
commit
487ecee143
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user