Skip to content

advantageous-overtake/lua-argon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[Continous Integration]

Installation

A rock is published to luarocks each time a new version is released.

Run the following command to install argon in your system.

sudo luarocks install argon

Or, if you preffer an user-specific installation.

luarocks install argon --local

How it works

argon is really simple, build -> parse.

You give it a definition with your desired parameters to match, and it gives you a parser object.

Yes, it is THAT simple.

The given table is a representation to C's argv array, this means that parameters cannot span multiple values in that array and thus makes it faster.

Documentation

argon.build

argon.build is the main entry point to argon, takes a definition table, and returns a parser.

local argon = require("argon")

local parser = argon
                    .build{
                      ["parameter-name"] = {
                        type = "boolean",
                        default_value = nil
                      }
                    }        

The definition table has the following structure:

{
  [string] = {
    ["type"] = "boolean|number|string",
    ["default_value"] = boolean|number|string (where type of 'default_value' is equal to 'type')
  }
}

.parse

<parser>.parse is the routine who parses already defined parameters from either the arg global (default) or the target_arguments parameter (if provided).

local argon = require("argon")

local cli_params = argon
                        .build{
                          ["parameter-name"] = {
                            type = "boolean",
                            default_value = true
                          }
                        }
                        .parse()

print( cli_params["parameter-name"] ) --> true

Giving a parameter a default value marks it as optional, by default, all parameters are required and will produce an error if not provided.

.inspect

<parser>.inspect is a routine who has the same API as <parser>.parse, but instead of returning the parse result, it returns its stringified representation.

local argon = require("argon")

local cli_params = argon
                        .build{
                          ["parameter-name"] = {
                            type = "boolean",
                            default_value = true
                          }
                        }
                        .inspect()

print( cli_params ) --> { ["parameter-name"] = true }

License

All files under this repository are licensed under the GPL-3.0 license.

About

Smart, short, and simple CLI (or not!) argument parser for Lua5.X.

Topics

Resources

License

Stars

Watchers

Forks

Languages