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:

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
    • title string Title message for your CLI. (default "")
    • tag string CLI Command to execute your program. (default "")
    • description string CLI description. (default "")
    • version string CLI version. (default "0.0.1")
    • prevent_help boolean Prevent help message if not command found. (default false)

Returns:

    Lummander
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
Lummander:apply_theme (theme)
Apply a theme

Parameters:

  • theme table or nil Theme to apply. See README.md file

Returns:

    Lummander
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:

    Command

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:

    Lummander

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:

  • message table or string Message splited by spaces and "". Execute Command if it is found.

Returns:

    Parsed
Lummander:run (command)
Run main action

Parameters:

  • command string Shell command to execute

Returns:

    Lummander

Logging

Lummander.log.info (text)
Log logging

Parameters:

Lummander.log.warn (text)
Warning logging

Parameters:

Lummander.log.error (text)
Error logging

Parameters:

generated by LDoc 1.4.6 Last updated 2019-10-12 17:17:18