Desvelao / lummander

Create a simple CLI with Lua.
https://desvelao.github.io/lummander
MIT License
57 stars 3 forks source link

is it possible to make an option required ? #5

Closed amirhossein-ka closed 2 years ago

amirhossein-ka commented 3 years ago

hello i want to get input like this ./myapp command -c <input> is it possible to make this option required or i need to get it from command ?

Desvelao commented 2 years ago

Hi @amirhossein-ka ,

The options can't be required.

You have some workarounds:

Command definition:

Object command definition in file:

return {
    command = "command <input>",
    description = "My command description",
    action = function(parsed, command, lum)
         print("My command input is" .. parsed.input)
    end
}

Command definition:

Object command definition in file if you load commands from files as explained here:

return {
    command = "command",
    description = "My command description",
    options = {
        {short = "c", long = "command", description = "Command option description", type = "normal"}
    },
    action = function(parsed, command, lum)
        if (not parsed.command) then return print("The --command/-c flag is required") end
                ....
    end
}