App
#struct AppA command line program and its commands.
| Name | Type | Description |
|---|---|---|
name | str = "" | The program's name. |
desc | str = "" | The program's description. |
version | str = "" | The program's version. |
cmd_names | Vector<str> | The names of the commands. |
cmd_descs | Vector<str> | The descriptions of the commands. |
import cli
import str
func run(app &: cli.App, line: str):
args := str.Split(line, " ")
command := cli.Dispatch(app, args)
if command == cli.CmdHelp:
println "help was asked for"
else command == cli.CmdVersion:
println "version:", app.version
else command == cli.CmdUnknown:
println "unknown command"
else:
println "running:", command, cli.RemainingArgs(args)
end
args.Free()
end
func main:
mut app := cli.New("salamctl", "project management", "1.0.0")
cli.Register(app, "build", "build the project")
cli.Register(app, "test", "run the tests")
println cli.HasCommand(app, "build"), cli.CommandDesc(app, "test")
each line in ["build --fast", "--help", "--version", "deploy"]:
run(app, line)
end
print cli.Usage(app)
endtrue run the tests running: build ["--fast"] help was asked for version: 1.0.0 unknown command salamctl 1.0.0 project management Usage: salamctl <command> [options] Commands: build build the project test run the tests Run 'salamctl <command> --help' for help on a specific command.