mirror of
				https://github.com/TangentFoxy/argparse.git
				synced 2025-10-24 20:35:02 +00:00 
			
		
		
		
	renamed largparse -> argparse; imported testing setup from literal
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| *~ | ||||
| *.luac | ||||
							
								
								
									
										12
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								.travis.yml
									
									
									
									
									
								
							| @@ -1,9 +1,15 @@ | ||||
| language: c | ||||
|  | ||||
| env: | ||||
|   - LUA="Lua 5.1" | ||||
|   - LUA="Lua 5.2" | ||||
|   - LUA="LuaJIT 2.0" | ||||
|  | ||||
| before_install: | ||||
|   - bash .travis_setup.sh | ||||
|  | ||||
| install: | ||||
|   - sudo apt-get install luarocks | ||||
|   - sudo luarocks make rockspecs/argparse-git-1.rockspec | ||||
|   - sudo luarocks install busted | ||||
|   - sudo luarocks install 30log | ||||
|   - sudo luarocks make rockspecs/largparse-lrcompat-1.rockspec | ||||
|  | ||||
| script: "busted spec" | ||||
|   | ||||
							
								
								
									
										33
									
								
								.travis_setup.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								.travis_setup.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| # A script for setting up environment for travis-ci testing.  | ||||
| # Sets up Lua and Luarocks.  | ||||
| # LUA must be "Lua 5.1", "Lua 5.2" or "LuaJIT 2.0".  | ||||
|  | ||||
| if [ "$LUA" == "LuaJIT 2.0" ]; then | ||||
|   curl http://luajit.org/download/LuaJIT-2.0.2.tar.gz | tar xz | ||||
|   cd LuaJIT-2.0.2 | ||||
|   make && sudo make install | ||||
|   cd ..; | ||||
| else | ||||
|   if [ "$LUA" == "Lua 5.1" ]; then | ||||
|     curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz | ||||
|     cd lua-5.1.5; | ||||
|   elif [ "$LUA" == "Lua 5.2" ]; then | ||||
|     curl http://www.lua.org/ftp/lua-5.2.3.tar.gz | tar xz | ||||
|     cd lua-5.2.3; | ||||
|   fi | ||||
|  | ||||
|   sudo make linux install | ||||
|   cd ..; | ||||
| fi | ||||
|  | ||||
| curl http://luarocks.org/releases/luarocks-2.1.1.tar.gz | tar xz | ||||
| cd luarocks-2.1.1 | ||||
|  | ||||
| if [ "$LUA" == "LuaJIT 2.0" ]; then | ||||
|   ./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0; | ||||
| else | ||||
|   ./configure; | ||||
| fi | ||||
|  | ||||
| make && sudo make install | ||||
| cd .. | ||||
| @@ -1,4 +1,4 @@ | ||||
| largparse | ||||
| argparse | ||||
| ========= | ||||
|  | ||||
| Feature-rich command line parser for Lua inspired by argparse for Python.  | ||||
| @@ -9,9 +9,9 @@ Something already works: | ||||
|  | ||||
| ```lua | ||||
|  | ||||
| local largparse = require "largparse" | ||||
| local argparse = require "argparse" | ||||
|  | ||||
| local parser = largparse.parser() | ||||
| local parser = argparse.parser() | ||||
|  | ||||
| parser:argument("input", { | ||||
|    args = 2 | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| package = "largparse" | ||||
| version = "wip-1" | ||||
| package = "argparse" | ||||
| version = "git-1" | ||||
| source = { | ||||
|    url = "src" | ||||
|    url = "git://github.com/mpeterv/literal.git" | ||||
| } | ||||
| description = { | ||||
|    summary = "*** please specify description summary ***", | ||||
| @@ -16,8 +16,8 @@ dependencies = { | ||||
| build = { | ||||
|    type = "builtin", | ||||
|    modules = { | ||||
|       largparse = "src/largparse.lua", | ||||
|       ["largparse.state"] = "src/state.lua", | ||||
|       ["largparse.utils"] = "src/utils.lua" | ||||
|       argparse = "src/argparse.lua", | ||||
|       ["argparse.state"] = "src/state.lua", | ||||
|       ["argparse.utils"] = "src/utils.lua" | ||||
|    } | ||||
| } | ||||
| @@ -1,22 +0,0 @@ | ||||
| package = "largparse" | ||||
| version = "lrcompat-1" | ||||
| source = { | ||||
|    url = "src" | ||||
| } | ||||
| description = { | ||||
|    summary = "*** please specify description summary ***", | ||||
|    detailed = "*** please enter a detailed description ***", | ||||
|    homepage = "*** please enter a project homepage ***", | ||||
|    license = "MIT/X11" | ||||
| } | ||||
| dependencies = { | ||||
|    "lua >= 5.1, < 5.3" | ||||
| } | ||||
| build = { | ||||
|    type = "builtin", | ||||
|    modules = { | ||||
|       largparse = "src/largparse.lua", | ||||
|       ["largparse.state"] = "src/state.lua", | ||||
|       ["largparse.utils"] = "src/utils.lua" | ||||
|    } | ||||
| } | ||||
| @@ -1,4 +1,4 @@ | ||||
| local largparse = require "largparse" | ||||
| local argparse = require "argparse" | ||||
|  | ||||
| describe("tests related to positional arguments", function() | ||||
|    local function curry(f, ...) | ||||
| @@ -8,20 +8,20 @@ describe("tests related to positional arguments", function() | ||||
|  | ||||
|    describe("passing correct arguments", function() | ||||
|       it("handles empty parser correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          local args = parser:parse({}) | ||||
|          assert.same(args, {}) | ||||
|       end) | ||||
|  | ||||
|       it("handles one argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument "foo" | ||||
|          local args = parser:parse({"bar"}) | ||||
|          assert.same(args, {foo = "bar"}) | ||||
|       end) | ||||
|  | ||||
|       it("handles several arguments correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument "foo1" | ||||
|          parser:argument "foo2" | ||||
|          local args = parser:parse({"bar", "baz"}) | ||||
| @@ -29,7 +29,7 @@ describe("tests related to positional arguments", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles multi-argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo", { | ||||
|             args = "*" | ||||
|          }) | ||||
| @@ -38,7 +38,7 @@ describe("tests related to positional arguments", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles restrained multi-argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo", { | ||||
|             args = "2-4" | ||||
|          }) | ||||
| @@ -47,7 +47,7 @@ describe("tests related to positional arguments", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles several multi-arguments correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo1", { | ||||
|             args = "1-2" | ||||
|          }) | ||||
| @@ -61,14 +61,14 @@ describe("tests related to positional arguments", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles hyphen correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument "foo" | ||||
|          local args = parser:parse({"-"}) | ||||
|          assert.same(args, {foo = "-"}) | ||||
|       end) | ||||
|  | ||||
|       it("handles double hyphen correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument "foo" | ||||
|          local args = parser:parse({"--", "-q"}) | ||||
|          assert.same(args, {foo = "-q"}) | ||||
| @@ -76,45 +76,45 @@ describe("tests related to positional arguments", function() | ||||
|    end) | ||||
|  | ||||
|    describe("passing incorrect arguments", function() | ||||
|       local old_parser = largparse.parser | ||||
|       local old_parser = argparse.parser | ||||
|  | ||||
|       setup(function() | ||||
|          largparse.parser = old_parser:extends() | ||||
|          function largparse.parser:error(fmt, ...) | ||||
|          argparse.parser = old_parser:extends() | ||||
|          function argparse.parser:error(fmt, ...) | ||||
|             error(fmt:format(...)) | ||||
|          end | ||||
|       end) | ||||
|  | ||||
|  | ||||
|       it("handles extra arguments with empty parser correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|  | ||||
|          assert.has_error(curry(parser.parse, parser, {"foo"}), "too many arguments") | ||||
|       end) | ||||
|  | ||||
|       it("handles extra arguments with one argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument "foo" | ||||
|  | ||||
|          assert.has_error(curry(parser.parse, parser, {"bar", "baz"}), "too many arguments") | ||||
|       end) | ||||
|  | ||||
|       it("handles sudden option correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument "foo" | ||||
|  | ||||
|          assert.has_error(curry(parser.parse, parser, {"-q"}), "unknown option -q") | ||||
|       end) | ||||
|  | ||||
|       it("handles too few arguments with one argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument "foo" | ||||
|  | ||||
|          assert.has_error(curry(parser.parse, parser, {}), "too few arguments") | ||||
|       end) | ||||
|  | ||||
|       it("handles extra arguments with several arguments correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument "foo1" | ||||
|          parser:argument "foo2" | ||||
|  | ||||
| @@ -122,7 +122,7 @@ describe("tests related to positional arguments", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles too few arguments with several arguments correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument "foo1" | ||||
|          parser:argument "foo2" | ||||
|  | ||||
| @@ -130,7 +130,7 @@ describe("tests related to positional arguments", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles too few arguments with multi-argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo", { | ||||
|             args = "+" | ||||
|          }) | ||||
| @@ -138,7 +138,7 @@ describe("tests related to positional arguments", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles too many arguments with multi-argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo", { | ||||
|             args = "2-4" | ||||
|          }) | ||||
| @@ -146,7 +146,7 @@ describe("tests related to positional arguments", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles too few arguments with multi-argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo", { | ||||
|             args = "2-4" | ||||
|          }) | ||||
| @@ -154,7 +154,7 @@ describe("tests related to positional arguments", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles too many arguments with several multi-arguments correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo1", { | ||||
|             args = "1-2" | ||||
|          }) | ||||
| @@ -165,7 +165,7 @@ describe("tests related to positional arguments", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles too few arguments with several multi-arguments correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo1", { | ||||
|             args = "1-2" | ||||
|          }) | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| local largparse = require "largparse" | ||||
| local argparse = require "argparse" | ||||
|  | ||||
| describe("tests related to default values", function() | ||||
|    describe("default values for arguments", function() | ||||
|       it("handles default argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo", { | ||||
|             default = "bar" | ||||
|          }) | ||||
| @@ -12,7 +12,7 @@ describe("tests related to default values", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles default multi-argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo", { | ||||
|             args = 3, | ||||
|             default = "bar" | ||||
| @@ -22,7 +22,7 @@ describe("tests related to default values", function() | ||||
|       end) | ||||
|  | ||||
|       it("does not use default values if not needed", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:argument("foo", { | ||||
|             args = "1-2", | ||||
|             default = "bar" | ||||
| @@ -34,7 +34,7 @@ describe("tests related to default values", function() | ||||
|  | ||||
|    describe("default values for options", function() | ||||
|       it("handles option with default value correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-f", "--foo", { | ||||
|             default = "bar" | ||||
|          }) | ||||
| @@ -43,7 +43,7 @@ describe("tests related to default values", function() | ||||
|       end) | ||||
|  | ||||
|       it("doesn't use default if option is not invoked", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-f", "--foo", { | ||||
|             default = "bar" | ||||
|          }) | ||||
| @@ -52,7 +52,7 @@ describe("tests related to default values", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles default multi-argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-f", "--foo", { | ||||
|             args = 3, | ||||
|             default = "bar" | ||||
| @@ -62,7 +62,7 @@ describe("tests related to default values", function() | ||||
|       end) | ||||
|  | ||||
|       it("does not use default values if not needed", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|           parser:option("-f", "--foo", { | ||||
|             args = "1-2", | ||||
|             default = "bar" | ||||
| @@ -72,7 +72,7 @@ describe("tests related to default values", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles multi-count options with default value correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|           parser:option("-f", "--foo", { | ||||
|             count = "*", | ||||
|             default = "bar" | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| local largparse = require "largparse" | ||||
| local argparse = require "argparse" | ||||
|  | ||||
| describe("tests related to options", function() | ||||
|    local function curry(f, ...) | ||||
| @@ -8,28 +8,28 @@ describe("tests related to options", function() | ||||
|  | ||||
|    describe("passing correct options", function() | ||||
|       it("handles no options passed correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-s", "--server") | ||||
|          local args = parser:parse({}) | ||||
|          assert.same(args, {}) | ||||
|       end) | ||||
|  | ||||
|       it("handles one option correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-s", "--server") | ||||
|          local args = parser:parse({"--server", "foo"}) | ||||
|          assert.same(args, {server = "foo"}) | ||||
|       end) | ||||
|  | ||||
|       it("handles GNU-style long options", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-s", "--server") | ||||
|          local args = parser:parse({"--server=foo"}) | ||||
|          assert.same(args, {server = "foo"}) | ||||
|       end) | ||||
|  | ||||
|       it("handles GNU-style long options even when it could take more arguments", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-s", "--server", { | ||||
|             args = "*" | ||||
|          }) | ||||
| @@ -38,7 +38,7 @@ describe("tests related to options", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles GNU-style long options for multi-argument options", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-s", "--server", { | ||||
|             args = "1-2" | ||||
|          }) | ||||
| @@ -47,21 +47,21 @@ describe("tests related to options", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles short option correclty", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-s", "--server") | ||||
|          local args = parser:parse({"-s", "foo"}) | ||||
|          assert.same(args, {server = "foo"}) | ||||
|       end) | ||||
|  | ||||
|       it("handles flag correclty", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:flag("-q", "--quiet") | ||||
|          local args = parser:parse({"--quiet"}) | ||||
|          assert.same(args, {quiet = true}) | ||||
|       end) | ||||
|  | ||||
|       it("handles combined flags correclty", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:flag("-q", "--quiet") | ||||
|          parser:flag("-f", "--fast") | ||||
|          local args = parser:parse({"-qf"}) | ||||
| @@ -69,14 +69,14 @@ describe("tests related to options", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles short options without space between option and argument", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-s", "--server") | ||||
|          local args = parser:parse({"-sfoo"}) | ||||
|          assert.same(args, {server = "foo"}) | ||||
|       end) | ||||
|  | ||||
|       it("handles flags combined with short option correclty", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:flag("-q", "--quiet") | ||||
|          parser:option("-s", "--server") | ||||
|          local args = parser:parse({"-qsfoo"}) | ||||
| @@ -85,7 +85,7 @@ describe("tests related to options", function() | ||||
|  | ||||
|       describe("Options with optional argument", function() | ||||
|          it("handles emptiness correctly", function() | ||||
|             local parser = largparse.parser() | ||||
|             local parser = argparse.parser() | ||||
|             parser:option("-p", "--password", { | ||||
|                args = "?" | ||||
|             }) | ||||
| @@ -94,7 +94,7 @@ describe("tests related to options", function() | ||||
|          end) | ||||
|  | ||||
|          it("handles option without argument correctly", function() | ||||
|             local parser = largparse.parser() | ||||
|             local parser = argparse.parser() | ||||
|             parser:option("-p", "--password", { | ||||
|                args = "?" | ||||
|             }) | ||||
| @@ -103,7 +103,7 @@ describe("tests related to options", function() | ||||
|          end) | ||||
|  | ||||
|          it("handles option with argument correctly", function() | ||||
|             local parser = largparse.parser() | ||||
|             local parser = argparse.parser() | ||||
|             parser:option("-p", "--password", { | ||||
|                args = "?" | ||||
|             }) | ||||
| @@ -113,7 +113,7 @@ describe("tests related to options", function() | ||||
|       end) | ||||
|  | ||||
|       it("handles multi-argument options correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("--pair", { | ||||
|             args = 2 | ||||
|          }) | ||||
| @@ -123,7 +123,7 @@ describe("tests related to options", function() | ||||
|  | ||||
|       describe("Multi-count options", function() | ||||
|          it("handles multi-count option correctly", function() | ||||
|             local parser = largparse.parser() | ||||
|             local parser = argparse.parser() | ||||
|             parser:option("-e", "--exclude", { | ||||
|                count = "*" | ||||
|             }) | ||||
| @@ -132,7 +132,7 @@ describe("tests related to options", function() | ||||
|          end) | ||||
|  | ||||
|          it("handles not used multi-count option correctly", function() | ||||
|             local parser = largparse.parser() | ||||
|             local parser = argparse.parser() | ||||
|             parser:option("-e", "--exclude", { | ||||
|                count = "*" | ||||
|             }) | ||||
| @@ -141,7 +141,7 @@ describe("tests related to options", function() | ||||
|          end) | ||||
|  | ||||
|          it("handles multi-count multi-argument option correctly", function() | ||||
|             local parser = largparse.parser() | ||||
|             local parser = argparse.parser() | ||||
|             parser:option("-e", "--exclude", { | ||||
|                count = "*", | ||||
|                args = 2 | ||||
| @@ -151,7 +151,7 @@ describe("tests related to options", function() | ||||
|          end) | ||||
|  | ||||
|          it("handles multi-count option with optional argument correctly", function() | ||||
|             local parser = largparse.parser() | ||||
|             local parser = argparse.parser() | ||||
|             parser:option("-w", "--why", "--why-would-someone-use-this", { | ||||
|                count = "*", | ||||
|                args = "?" | ||||
| @@ -161,7 +161,7 @@ describe("tests related to options", function() | ||||
|          end) | ||||
|  | ||||
|          it("handles multi-count flag correctly", function() | ||||
|             local parser = largparse.parser() | ||||
|             local parser = argparse.parser() | ||||
|             parser:flag("-q", "--quiet", { | ||||
|                count = "*" | ||||
|             }) | ||||
| @@ -170,7 +170,7 @@ describe("tests related to options", function() | ||||
|          end) | ||||
|  | ||||
|          it("overwrites old invocations", function() | ||||
|             local parser = largparse.parser() | ||||
|             local parser = argparse.parser() | ||||
|             parser:option("-u", "--user", { | ||||
|                count = "0-2" | ||||
|             }) | ||||
| @@ -179,7 +179,7 @@ describe("tests related to options", function() | ||||
|          end) | ||||
|  | ||||
|          it("handles not used multi-count flag correctly", function() | ||||
|             local parser = largparse.parser() | ||||
|             local parser = argparse.parser() | ||||
|             parser:flag("-q", "--quiet", { | ||||
|                count = "*" | ||||
|             }) | ||||
| @@ -190,35 +190,35 @@ describe("tests related to options", function() | ||||
|    end) | ||||
|  | ||||
|    describe("passing incorrect options", function() | ||||
|       local old_parser = largparse.parser | ||||
|       local old_parser = argparse.parser | ||||
|  | ||||
|       setup(function() | ||||
|          largparse.parser = old_parser:extends() | ||||
|          function largparse.parser:error(fmt, ...) | ||||
|          argparse.parser = old_parser:extends() | ||||
|          function argparse.parser:error(fmt, ...) | ||||
|             error(fmt:format(...)) | ||||
|          end | ||||
|       end) | ||||
|  | ||||
|       it("handles lack of required argument correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-s", "--server") | ||||
|          assert.has_error(curry(parser.parse, parser, {"--server"}), "too few arguments") | ||||
|       end) | ||||
|  | ||||
|       it("handles too many arguments correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:option("-s", "--server") | ||||
|          assert.has_error(curry(parser.parse, parser, {"-sfoo", "bar"}), "too many arguments") | ||||
|       end) | ||||
|  | ||||
|       it("doesn't accept GNU-like long options when it doesn't need arguments", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:flag("-q", "--quiet") | ||||
|          assert.has_error(curry(parser.parse, parser, {"--quiet=very_quiet"}), "option --quiet doesn't take arguments") | ||||
|       end) | ||||
|  | ||||
|       it("handles too many invocations correctly", function() | ||||
|          local parser = largparse.parser() | ||||
|          local parser = argparse.parser() | ||||
|          parser:flag("-q", "--quiet", { | ||||
|             count = 1, | ||||
|             no_overwrite = true | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| local utils = require "largparse.utils" | ||||
| local utils = require "argparse.utils" | ||||
|  | ||||
| describe("tests related to utils.parse_boundaries", function() | ||||
|    it("handles * correctly", function() | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| local largparse = {} | ||||
| local argparse = {} | ||||
| 
 | ||||
| local class = require "30log" | ||||
| 
 | ||||
| local State = require "largparse.state" | ||||
| local utils = require "largparse.utils" | ||||
| local State = require "argparse.state" | ||||
| local utils = require "argparse.utils" | ||||
| 
 | ||||
| local Parser = class() | ||||
| 
 | ||||
| @@ -262,6 +262,6 @@ function Parser:parse(args) | ||||
|    return result | ||||
| end | ||||
| 
 | ||||
| largparse.parser = Parser | ||||
| argparse.parser = Parser | ||||
| 
 | ||||
| return largparse | ||||
| return argparse | ||||
| @@ -1,21 +0,0 @@ | ||||
| local largparse = require "largparse" | ||||
| local serpent = require "serpent" | ||||
|  | ||||
| local parser = largparse.parser() | ||||
|  | ||||
| parser:argument("input", { | ||||
|    args = 2 | ||||
| }) | ||||
|  | ||||
| parser:mutually_exclusive( | ||||
|    parser:flag("-q", "--quiet"), | ||||
|    parser:option("-s", "--server") | ||||
| ) | ||||
|  | ||||
| local run = parser:command "run" | ||||
|  | ||||
| run:flag("-f", "--fast") | ||||
|  | ||||
| local args = parser:parse() | ||||
|  | ||||
| print(serpent.block(args)) | ||||
		Reference in New Issue
	
	Block a user