A micro-framework for building Positional CLIs in Lua.
- Supports ANSI colors
- Types of arguments:
- <name>
- Required -> If not provided, the program displays an error and stops execution.
- [name]
- Optional -> If not provided, returns an empty string "".
- <name>
- Cli:new()
- Cli:new(cli_name, description, error_header, default_command)
- Cli:new_command()
- Cli:new_command(command_name, parameters_str, description, callback)
- Cli:run()
- Cli:run(arg_list)
- callback
- The function that contains the logic of the command, receiving (args, instance)
- instance:
- name;
- description;
- error_header;
- default_command;
- commands.
- instance:
- The function that contains the logic of the command, receiving (args, instance)
local Cli = require("CliLua")
--local app = Cli:new(cli_name, description, error_header, default_command)
local app = Cli:new("App", "This program is an example of how to use the 'cli' module")
-- Example payment command
app:new_command("pay", "<person> <amount> [reason]", "Send payments to users", function(args)
print("Sending $" .. args.amount .. " for " .. args.person)
if args.reason ~= "" then
print("Reference: " .. args.reason)
end
end)
app:new_command("version", nil, "Command to view the CLI version.", function(args, instance)
print(instance.name.." : v0.1.0")
end)
app:run(arg)