GithubHelp home page GithubHelp logo

vanillaiice / lua-cli Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 24 KB

lua-cli is a simple module to build command line interfaces in Lua.

License: GNU General Public License v3.0

Lua 98.79% Shell 1.21%

lua-cli's Introduction

lua-cli

lua-cli is a simple module to build command line interfaces in Lua.

It is heavily inspired by the amazing urfave/cli golang package.

Usage

Here is a minimal working example:

-- kitchen.lua

-- import the cli module
local cli = require("cli")

-- create the app
local app = cli.app("kitchen", "1.0.0", "gordon ramsay", "cook in the kitchen")

-- add global flags
app:addFlags(cli.newFlag("verbose", "v", "be verbose", false, false))

-- add commands
app:addCommands(
	cli.newCommand(
		"cook",
		"c",
		"cook something",
		{cli.newFlag("dish", "d", "dish to cook", "beef wellington", false)},
		function(globalFlags, localFlags)
			if globalFlags.verbose then
				print("[INFO]: cooking " .. localFlags.dish)
			end

			print("here is your " .. localFlags.dish .. '!')

			if globalFlags.verbose then
				print("[INFO]: enjoy!")
			end
		end
	)
)

-- run the app
app:run({"-v", "true", "cook", "-d", "ramen"})

-- in practice, you'd pass the arg table to the run function,
-- and then run it like so: lua kitchen.lua -v true cook -d ramen
app:run(arg)

print('\n')

-- print help
app:help()
# output of help
NAME:
  kitchen

DESCRIPTION:
  cook in the kitchen

VERSION:
  1.0.0

AUTHOR:
  gordon ramsay

COMMANDS:
  cook, c	cook something

GLOBAL OPTIONS:
  --verbose, -v	be verbose

you can also check the test directory for more examples.

Author

vanillaiice

License

GPLv3

lua-cli's People

Contributors

vanillaiice avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.