Skip to main content

core.cli

Provides the CLI parser functionality.

local cli = require "core.cli"

app_description

(field) app_description: string

Application description


app_name

(field) app_name: string

Application name


app_version

(field) app_version: string

Application version


commands

(field) commands: table<string, core.cli.command>

List of registered commands


core.cli.command

Representation of a command line subcommand.

arguments

(field) arguments: table<string, string>?

Description of the arguments printed on command help.


command

(field) command: string

Subcommand name invoked with app mycommand


description

(field) description: string

Description used for the command when running app help


execute

(field) execute: fun(flags: core.cli.flag[], arguments: string[])?

Function called when the command is invoked by the user


exit_editor

(field) exit_editor: boolean?

Flag true by default which causes the editor to not launch when command is executed


flags

(field) flags: core.cli.flag[]?

Optional list of flags that can be used as part of the command


long_description

(field) long_description: string?

Optional more detailed description that shows how to use the command


max_arguments

(field) max_arguments: integer?

The maximum amount of arguments required for the command where -1 is any


min_arguments

(field) min_arguments: integer?

The minimum amount of arguments required for the command


subcommands

(field) subcommands: core.cli.command[]?

Optional list of subcommands that belong to the parent subcommand


usage

(field) usage: string?

Single line brief of using the command, eg: [options] [<argument>]


core.cli.flag

Representation of a command line flag.

description

(field) description: string

Description used for the flag when running app help mycommand


name

(field) name: string

Long name of the flag eg: my-flag for --my-flag


short_name

(field) short_name: string

Short name eg: m for -m


type

(field) type: ("boolean"|"empty"|"list"|"number"|"string")?

Data type of the flag if an argument/value can be given to it


value

(field) value: (boolean|string|number|table)?

Value assigned to the flag


colorize

function core.cli.colorize(text: string, color: "blue"|"gray"|"green"|"liteblue"|"purple"...(+2))
-> colorized_text: string

Adds color to given text on non windows systems.

color:
| "red"
| "green"
| "yellow"
| "purple"
| "blue"
| "liteblue"
| "gray"

get_default

function core.cli.get_default()
-> (core.cli.command)?

Get the default command used by the CLI parser.


parse

function core.cli.parse(args: string[])

Parse the command line arguments and execute the applicable commands.


function core.cli.print_help(command?: core.cli.command)

Display the generated application help or a specific command help.


register

function core.cli.register(command: core.cli.command, overwrite?: boolean)

Add a new command to the cli parser.


set_default

function core.cli.set_default(command: core.cli.command)

Set the default command used by the CLI parser.


unregister

function core.cli.unregister(command: string)

Removes an existing command from the cli parser.