Skip to content

MathV2023/CliLua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLI made in Lua

A micro-framework for building Positional CLIs in Lua.

Features

  • 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 "".
  • 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.

Example:

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)

About

A micro-framework for building Positional CLIs in Lua.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages