mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
0.4.0 release
This commit is contained in:
66
README.md
66
README.md
@@ -2,47 +2,47 @@
|
|||||||
|
|
||||||
[](https://travis-ci.org/mpeterv/argparse)
|
[](https://travis-ci.org/mpeterv/argparse)
|
||||||
|
|
||||||
argparse is a feature-rich command line parser for Lua inspired by argparse for Python.
|
Argparse is a feature-rich command line parser for Lua inspired by argparse for Python.
|
||||||
|
|
||||||
argparse supports positional arguments, options, flags, optional arguments, subcommands and more. argparse automatically generates usage, help and error messages.
|
Argparse supports positional arguments, options, flags, optional arguments, subcommands and more. Argparse automatically generates usage, help and error messages.
|
||||||
|
|
||||||
Quick glance:
|
Simple example:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- script.lua
|
-- script.lua
|
||||||
local argparse = require "argparse"
|
local argparse = require "argparse"
|
||||||
local parser = argparse()
|
|
||||||
:description "An example."
|
local parser = argparse("script", "An example.")
|
||||||
parser:argument "input"
|
parser:argument("input", "Input file.")
|
||||||
:description "Input file."
|
parser:option("-o --output", "Output file.", "a.out")
|
||||||
parser:option "-o" "--output"
|
parser:option("-I --include", "Include locations."):count("*")
|
||||||
:default "a.out"
|
|
||||||
:description "Output file."
|
|
||||||
parser:option "-I" "--include"
|
|
||||||
:count "*"
|
|
||||||
:description "Include locations."
|
|
||||||
local args = parser:parse()
|
local args = parser:parse()
|
||||||
prettyprint(args)
|
print(args) -- Assuming print is patched to handle tables nicely.
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ lua script.lua foo
|
$ lua script.lua foo
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```lua
|
||||||
input: foo
|
{
|
||||||
output: a.out
|
input = "foo",
|
||||||
include: {}
|
output = "a.out",
|
||||||
|
include = {}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ lua script.lua foo -I/usr/local/include -I/src -o bar
|
$ lua script.lua foo -I/usr/local/include -Isrc -o bar
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```lua
|
||||||
input: foo
|
{
|
||||||
output: bar
|
input = "foo",
|
||||||
include: {/usr/local/include, /src}
|
output = "bar",
|
||||||
|
include = {"/usr/local/include", "src"}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -50,7 +50,7 @@ $ lua script.lua foo bar
|
|||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage: script.lua [-o <output>] [-I <include>] [-h] <input>
|
Usage: script [-o <output>] [-I <include>] [-h] <input>
|
||||||
|
|
||||||
Error: too many arguments
|
Error: too many arguments
|
||||||
```
|
```
|
||||||
@@ -60,7 +60,7 @@ $ lua script.lua --help
|
|||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage: script.lua [-o <output>] [-I <include>] [-h] <input>
|
Usage: script [-o <output>] [-I <include>] [-h] <input>
|
||||||
|
|
||||||
An example.
|
An example.
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ $ lua script.lua foo --outptu=bar
|
|||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage: script.lua [-o <output>] [-I <include>] [-h] <input>
|
Usage: script [-o <output>] [-I <include>] [-h] <input>
|
||||||
|
|
||||||
Error: unknown option '--outptu'
|
Error: unknown option '--outptu'
|
||||||
Did you mean '--output'?
|
Did you mean '--output'?
|
||||||
@@ -95,26 +95,26 @@ Did you mean '--output'?
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Using luarocks
|
### Using LuaRocks
|
||||||
|
|
||||||
Installing argparse using luarocks is simple.
|
Installing argparse using [LuaRocks](http://luarocks.org) is simple:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ luarocks install argparse
|
$ luarocks install argparse
|
||||||
```
|
```
|
||||||
|
|
||||||
### Without luarocks
|
### Without LuaRocks
|
||||||
|
|
||||||
Download `src/argparse.lua` file and put it into the directory for Lua libraries or your working directory.
|
Download `src/argparse.lua` file and put it into the directory for Lua libraries or your working directory.
|
||||||
|
|
||||||
## Tutorial
|
## Tutorial
|
||||||
|
|
||||||
The tutorial is available [online](http://mpeterv.github.io/argparse/) and in the `doc` directory. If argparse was installed using luarocks 2.1.2 or later, it can be viewed using `luarocks doc argparse` command.
|
The tutorial is available [online](http://argparse.readthedocs.org) and in the `doc` directory. If argparse has been installed using LuaRocks 2.1.2 or later, it can be viewed using `luarocks doc argparse` command.
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
argparse comes with a testing suite located in `spec` directory. [busted](http://olivinelabs.com/busted/) is required for testing, it can be installed using luarocks. Run the tests using `busted spec` command from the argparse folder.
|
argparse comes with a testing suite located in `spec` directory. [busted](http://olivinelabs.com/busted/) is required for testing, it can be installed using LuaRocks. Run the tests using `busted spec` command from the argparse folder.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
argparse is licensed under the same terms as Lua itself(MIT license).
|
argparse is licensed under the same terms as Lua itself (MIT license).
|
||||||
|
22
rockspecs/argparse-0.4.0-1.rockspec
Normal file
22
rockspecs/argparse-0.4.0-1.rockspec
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package = "argparse"
|
||||||
|
version = "0.4.0-1"
|
||||||
|
source = {
|
||||||
|
url = "git://github.com/mpeterv/argparse",
|
||||||
|
tag = "0.4.0"
|
||||||
|
}
|
||||||
|
description = {
|
||||||
|
summary = "A feature-rich command-line argument parser",
|
||||||
|
detailed = "Argparse supports positional arguments, options, flags, optional arguments, subcommands and more. Argparse automatically generates usage, help and error messages.",
|
||||||
|
homepage = "https://github.com/mpeterv/argparse",
|
||||||
|
license = "MIT/X11"
|
||||||
|
}
|
||||||
|
dependencies = {
|
||||||
|
"lua >= 5.1, < 5.4"
|
||||||
|
}
|
||||||
|
build = {
|
||||||
|
type = "builtin",
|
||||||
|
modules = {
|
||||||
|
argparse = "src/argparse.lua"
|
||||||
|
},
|
||||||
|
copy_directories = {"doc", "spec"}
|
||||||
|
}
|
Reference in New Issue
Block a user