Build a CLI Tool with Subcommands in Larzscript
Build a real command-line tool with named subcommands and auto-generated help, the shape every larzscript-* showcase app in this ecosystem uses.
cli.new()/cli.command()/cli.run() dispatch on the first argument; each command's handler gets parsed --flags and positional args.
larzscript pkg install cli
Code
import "cli" as cli
let app = cli.new("greet", "a tiny greeter")
cli.command(app, "hello", "say hello: hello NAME", fn(a) {
print("hello, " + a["positional"][0] + "!")
})
cli.run(app, ["hello", "Ada"])Output
hello, Ada!
Related
larzcliBuild CLI tools with subcommands→Parse Command-Line Arguments in LarzscriptParse --flag=value pairs and positional arguments out of argv, without a full CLI framework.→Read a File Line by Line in LarzscriptRead a text file's contents and split it into lines - the everyday first step of any script that processes a file.→Pretty-Print a Table in LarzscriptRender tabular data as an aligned ASCII table for the terminal, or Markdown for a README.→