Class Lummander
Lummander module
Tables
Lummander.theme | Theme table |
Fields
Lummander.chalk | Chalk |
Lummander.lfs | LuaFileSystem |
Lummander.pcall | Lummander Pcall |
Methods
Lummander:new (setup) | Create a Lummander instance |
Lummander:action (command, params) | Set a default action to execute if any command if found |
Lummander:apply_theme (theme) | Apply a theme |
Lummander:command (command[, description=""[, config={}]]) | Create a new command |
Lummander:commands_dir (folderpath) | Load command of a directory |
Lummander:execute (command, fn) | Execute command on shell |
Lummander:find_cmd (cmd_name) | Search a command by name |
Lummander:help ([ignore_flag=false]) | Print Help message |
Lummander:parse (message) | Parse message |
Lummander:run (command) | Run main action |
Logging
Lummander.log.info (text) | Log logging |
Lummander.log.warn (text) | Warning logging |
Lummander.log.error (text) | Error logging |
Tables
- Lummander.theme
-
Theme table
Fields:
- cli
- title ThemeColor
- text ThemeColor
- category ThemeColor
- command
- definition ThemeColor
- description ThemeColor
- argument ThemeColor
- option ThemeColor
- category ThemeColor
- primary ThemeColor
- secondary ThemeColor
- success ThemeColor
- warning ThemeColor
- error ThemeColor
- cli
Fields
- Lummander.chalk
-
Chalk
- chalk Chalk
- Lummander.lfs
-
LuaFileSystem
- lfs LuaFileSystem
- Lummander.pcall
-
Lummander Pcall
- pcall Pcall
See also:
Methods
- Lummander:new (setup)
-
Create a Lummander instance
Parameters:
- setup Options
Returns:
- Lummander:action (command, params)
-
Set a default action to execute if any command if found
Parameters:
- command function Default action
- params table Default params passed to Default action function
Returns:
- Lummander:apply_theme (theme)
-
Apply a theme
Parameters:
- theme table or nil Theme to apply. See README.md file
Returns:
- Lummander:command (command[, description=""[, config={}]])
-
Create a new command
Parameters:
- command string Parse that string to extract arguments names and their requirement.
- description string or table Command description or table as config. (default "")
- config Options.
- schema string Command schema. (optional)
- description string Command description. (default "")
- positional_args table Command description. (default {})
- options {options} CommandOptions (optional)
- hide boolean Hide from help command (default false)
- main boolean Set as main cli command (default false)
- action function Command action function. (optional)
Returns:
Usage:
lummander:command("mycmd <req1> [opt1] [...opt_array]", "My command description") -- you can chaining methods to define the command -- or create a command with full definition lummander:command("mycmd <req1> [opt1] [...opt_array]", "My command description", { positional_args = { req1 = "Description for required argument", opt1 = {description = "Description for optional argument", default = "my_default_value"}, opt_array = {description = "Description for optional arguments lieke array", default = {"1","2"}} }, hide = false main = false action = function(parsed, command, lummander) --do something here end }) -- or lummander:command("mycmd <req1> [opt1] [...opt_array]", { description = "My command description", positional_args = { req1 = "Description for required argument", opt1 = {description = "Description for optional argument", default = "my_default_value"}, opt_array = {description = "Description for optional arguments lieke array", default = {"1","2"}} }, hide = false main = false action = function(parsed, command, lummander) --do something here end }) -- or pass all like a table lummander:command({ shema = "mycmd <req1> [opt1] [...opt_array]", description = "My command description" , positional_args = { req1 = "Description for required argument", opt1 = {description = "Description for optional argument", default = "my_default_value"}, opt_array = {description = "Description for optional arguments lieke array", default = {"1","2"}} }, hide = false main = false action = function(parsed, command, lummander) --do something here end })
- Lummander:commands_dir (folderpath)
-
Load command of a directory
Parameters:
- folderpath string Relative path to load commands (.lua files). Use as require format.
Returns:
Usage:
--"commands_folder" is a folder in same directory that main lua file. lummander:commands_dir("commands_folder") -- or lummander:commands_dir("commands_folder.subfolder")
- Lummander:execute (command, fn)
-
Execute command on shell
Parameters:
- command string Shell command to execute
- fn optional function Callback to execute when the shell command finished
Returns:
-
optional string
- Lummander:find_cmd (cmd_name)
-
Search a command by name
Parameters:
- cmd_name string Command name to search.
Returns:
-
Command or nil
- Lummander:help ([ignore_flag=false])
-
Print Help message
Parameters:
- ignore_flag bool ignoreflag Ignore Lummander preventhelp to show hep message. If prevent_help option is placed in Lummander init, it ignores print Lummander:help() when it is called (default false)
- Lummander:parse (message)
-
Parse message
Parameters:
Returns:
- Lummander:run (command)
-
Run main action
Parameters:
- command string Shell command to execute
Returns: