Command-line applications
Parse options for a deploy command
The command library provides long and short options, defaults, boolean flags, required arguments, generated help, and subcommands. This is enough to build an operational CLI without adding an argument-parsing dependency.
After testing the script, geblang build packages it with the runtime as one executable for Linux, macOS, or Windows. See the full command example.
import cli.command as command;
import io;
let deploy = command.newCommand("deploy", "Deploy an application");
deploy.option(
command.newOption("env", "string")
.short("e")
.default("dev")
.help("target environment")
);
deploy.option(
command.newOption("dry-run", "bool")
.help("show the deployment plan")
);
let options = deploy.parse(["--env", "prod", "--dry-run"]);
io.println("environment: ${options["env"]}");
io.println("dry run: ${options["dry-run"]}");
Save it as deploy.gb and run geblang run deploy.gb. The parsed environment is prod and the dry-run flag is true.