diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2015-03-23 23:25:25 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2015-03-23 23:25:25 -0300 |
| commit | 7f7c006007c42376d711d71f42e5577d431c6b64 (patch) | |
| tree | e42419133bdccfc47760783402b5781e35b55882 /src | |
| parent | 68aa7aef29000099ab1dfebe92052e693fe18d64 (diff) | |
| download | luarocks-7f7c006007c42376d711d71f42e5577d431c6b64.tar.gz luarocks-7f7c006007c42376d711d71f42e5577d431c6b64.tar.bz2 luarocks-7f7c006007c42376d711d71f42e5577d431c6b64.zip | |
Add support for space in long option assignments.
Support assignments in long option in two tokens, so that
```
luarocks --only-from /foo/bar build luasocket
```
is accepted as a synonym to:
```
luarocks --only-from=/foo/bar build luasocket
```
(This is consistent with the GNU getopt handling of "--" long options.)
Closes #65.
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/command_line.lua | 15 | ||||
| -rw-r--r-- | src/luarocks/util.lua | 103 | ||||
| -rw-r--r-- | src/luarocks/write_rockspec.lua | 4 |
3 files changed, 100 insertions, 22 deletions
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index 96d7cb11..9cc34c42 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
| @@ -64,6 +64,9 @@ function command_line.run_command(...) | |||
| 64 | end | 64 | end |
| 65 | local nonflags = { util.parse_flags(unpack(args)) } | 65 | local nonflags = { util.parse_flags(unpack(args)) } |
| 66 | local flags = table.remove(nonflags, 1) | 66 | local flags = table.remove(nonflags, 1) |
| 67 | if flags.ERROR then | ||
| 68 | die(flags.ERROR.." See --help.") | ||
| 69 | end | ||
| 67 | 70 | ||
| 68 | if flags["from"] then flags["server"] = flags["from"] end | 71 | if flags["from"] then flags["server"] = flags["from"] end |
| 69 | if flags["only-from"] then flags["only-server"] = flags["only-from"] end | 72 | if flags["only-from"] then flags["only-server"] = flags["only-from"] end |
| @@ -126,16 +129,10 @@ function command_line.run_command(...) | |||
| 126 | end | 129 | end |
| 127 | 130 | ||
| 128 | if flags["branch"] then | 131 | if flags["branch"] then |
| 129 | if flags["branch"] == true or flags["branch"] == "" then | ||
| 130 | die("Argument error: use --branch=<branch-name>") | ||
| 131 | end | ||
| 132 | cfg.branch = flags["branch"] | 132 | cfg.branch = flags["branch"] |
| 133 | end | 133 | end |
| 134 | 134 | ||
| 135 | if flags["tree"] then | 135 | if flags["tree"] then |
| 136 | if flags["tree"] == true or flags["tree"] == "" then | ||
| 137 | die("Argument error: use --tree=<path>") | ||
| 138 | end | ||
| 139 | local named = false | 136 | local named = false |
| 140 | for _, tree in ipairs(cfg.rocks_trees) do | 137 | for _, tree in ipairs(cfg.rocks_trees) do |
| 141 | if type(tree) == "table" and flags["tree"] == tree.name then | 138 | if type(tree) == "table" and flags["tree"] == tree.name then |
| @@ -178,17 +175,11 @@ function command_line.run_command(...) | |||
| 178 | cfg.variables.SCRIPTS_DIR = cfg.deploy_bin_dir | 175 | cfg.variables.SCRIPTS_DIR = cfg.deploy_bin_dir |
| 179 | 176 | ||
| 180 | if flags["server"] then | 177 | if flags["server"] then |
| 181 | if flags["server"] == true then | ||
| 182 | die("Argument error: use --server=<url>") | ||
| 183 | end | ||
| 184 | local protocol, path = dir.split_url(flags["server"]) | 178 | local protocol, path = dir.split_url(flags["server"]) |
| 185 | table.insert(cfg.rocks_servers, 1, protocol.."://"..path) | 179 | table.insert(cfg.rocks_servers, 1, protocol.."://"..path) |
| 186 | end | 180 | end |
| 187 | 181 | ||
| 188 | if flags["only-server"] then | 182 | if flags["only-server"] then |
| 189 | if flags["only-server"] == true then | ||
| 190 | die("Argument error: use --only-server=<url>") | ||
| 191 | end | ||
| 192 | cfg.rocks_servers = { flags["only-server"] } | 183 | cfg.rocks_servers = { flags["only-server"] } |
| 193 | end | 184 | end |
| 194 | 185 | ||
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 40af35bd..6319ae14 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
| @@ -63,6 +63,63 @@ function util.matchquote(s) | |||
| 63 | return (s:gsub("[?%-+*%[%].%%()$^]","%%%1")) | 63 | return (s:gsub("[?%-+*%[%].%%()$^]","%%%1")) |
| 64 | end | 64 | end |
| 65 | 65 | ||
| 66 | local supported_flags = { | ||
| 67 | ["all"] = true, | ||
| 68 | ["api-key"] = "<key>", | ||
| 69 | ["append"] = true, | ||
| 70 | ["arch"] = "<arch>", | ||
| 71 | ["bin"] = true, | ||
| 72 | ["binary"] = true, | ||
| 73 | ["branch"] = "<branch-name>", | ||
| 74 | ["debug"] = true, | ||
| 75 | ["deps"] = true, | ||
| 76 | ["deps-mode"] = "<mode>", | ||
| 77 | ["detailed"] = "\"<text>\"", | ||
| 78 | ["extensions"] = true, | ||
| 79 | ["force"] = true, | ||
| 80 | ["from"] = "<server>", | ||
| 81 | ["help"] = true, | ||
| 82 | ["home"] = true, | ||
| 83 | ["homepage"] = true, | ||
| 84 | ["keep"] = true, | ||
| 85 | ["lib"] = true, | ||
| 86 | ["license"] = "\"<text>\"", | ||
| 87 | ["list"] = true, | ||
| 88 | ["local"] = true, | ||
| 89 | ["local-tree"] = true, | ||
| 90 | ["lr-bin"] = true, | ||
| 91 | ["lr-cpath"] = true, | ||
| 92 | ["lr-path"] = true, | ||
| 93 | ["lua-version"] = "<vers>", | ||
| 94 | ["modules"] = true, | ||
| 95 | ["mversion"] = true, | ||
| 96 | ["no-refresh"] = true, | ||
| 97 | ["nodeps"] = true, | ||
| 98 | ["old-versions"] = true, | ||
| 99 | ["only-from"] = "<server>", | ||
| 100 | ["only-server"] = "<server>", | ||
| 101 | ["only-sources"] = "<url>", | ||
| 102 | ["only-sources-from"] = "<url>", | ||
| 103 | ["outdated"] = true, | ||
| 104 | ["output"] = "<file>", | ||
| 105 | ["pack-binary-rock"] = true, | ||
| 106 | ["porcelain"] = true, | ||
| 107 | ["quick"] = true, | ||
| 108 | ["rock-dir"] = true, | ||
| 109 | ["rock-tree"] = true, | ||
| 110 | ["rockspec"] = true, | ||
| 111 | ["server"] = "<server>", | ||
| 112 | ["skip-pack"] = true, | ||
| 113 | ["source"] = true, | ||
| 114 | ["summary"] = "\"<text>\"", | ||
| 115 | ["tag"] = "<tag>", | ||
| 116 | ["timeout"] = "<seconds>", | ||
| 117 | ["to"] = "<path>", | ||
| 118 | ["tree"] = "<path>", | ||
| 119 | ["verbose"] = true, | ||
| 120 | ["version"] = true, | ||
| 121 | } | ||
| 122 | |||
| 66 | --- Extract flags from an arguments list. | 123 | --- Extract flags from an arguments list. |
| 67 | -- Given string arguments, extract flag arguments into a flags set. | 124 | -- Given string arguments, extract flag arguments into a flags set. |
| 68 | -- For example, given "foo", "--tux=beep", "--bla", "bar", "--baz", | 125 | -- For example, given "foo", "--tux=beep", "--bla", "bar", "--baz", |
| @@ -71,19 +128,53 @@ end | |||
| 71 | function util.parse_flags(...) | 128 | function util.parse_flags(...) |
| 72 | local args = {...} | 129 | local args = {...} |
| 73 | local flags = {} | 130 | local flags = {} |
| 74 | for i = #args, 1, -1 do | 131 | local i = 1 |
| 132 | local out = {} | ||
| 133 | local ignore_flags = false | ||
| 134 | while i <= #args do | ||
| 75 | local flag = args[i]:match("^%-%-(.*)") | 135 | local flag = args[i]:match("^%-%-(.*)") |
| 76 | if flag then | 136 | if flag == "--" then |
| 137 | ignore_flags = true | ||
| 138 | end | ||
| 139 | if flag and not ignore_flags then | ||
| 77 | local var,val = flag:match("([a-z_%-]*)=(.*)") | 140 | local var,val = flag:match("([a-z_%-]*)=(.*)") |
| 78 | if val then | 141 | if val then |
| 79 | flags[var] = val | 142 | local vartype = supported_flags[var] |
| 143 | if type(vartype) == "string" then | ||
| 144 | flags[var] = val | ||
| 145 | else | ||
| 146 | if vartype then | ||
| 147 | return { ERROR = "Invalid argument: flag --"..var.." does not take an parameter." } | ||
| 148 | else | ||
| 149 | return { ERROR = "Invalid argument: unknown flag --"..var.."." } | ||
| 150 | end | ||
| 151 | end | ||
| 80 | else | 152 | else |
| 81 | flags[flag] = true | 153 | local var = flag |
| 154 | local vartype = supported_flags[var] | ||
| 155 | if type(vartype) == "string" then | ||
| 156 | i = i + 1 | ||
| 157 | local val = args[i] | ||
| 158 | if not val then | ||
| 159 | return { ERROR = "Invalid argument: flag --"..var.."="..vartype.." expects a parameter." } | ||
| 160 | end | ||
| 161 | if val:match("^%-%-.*") then | ||
| 162 | return { ERROR = "Invalid argument: flag --"..var.."="..vartype.." expects a parameter (if you really want to pass "..val.." as an argument to --"..var..", use --"..var.."="..val..")." } | ||
| 163 | else | ||
| 164 | flags[var] = val | ||
| 165 | end | ||
| 166 | elseif vartype == true then | ||
| 167 | flags[var] = true | ||
| 168 | else | ||
| 169 | return { ERROR = "Invalid argument: unknown flag --"..var.."." } | ||
| 170 | end | ||
| 82 | end | 171 | end |
| 83 | table.remove(args, i) | 172 | else |
| 173 | table.insert(out, args[i]) | ||
| 84 | end | 174 | end |
| 175 | i = i + 1 | ||
| 85 | end | 176 | end |
| 86 | return flags, unpack(args) | 177 | return flags, unpack(out) |
| 87 | end | 178 | end |
| 88 | 179 | ||
| 89 | --- Build a sequence of flags for forwarding from one command to | 180 | --- Build a sequence of flags for forwarding from one command to |
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index 5b129ab0..fb3a120e 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua | |||
| @@ -209,10 +209,6 @@ function write_rockspec.run(...) | |||
| 209 | elseif not url_or_dir then | 209 | elseif not url_or_dir then |
| 210 | url_or_dir = version | 210 | url_or_dir = version |
| 211 | end | 211 | end |
| 212 | |||
| 213 | if flags["tag"] == true then | ||
| 214 | return nil, "Incorrect usage: --tag requires an argument. "..util.see_help("write_rockspec") | ||
| 215 | end | ||
| 216 | 212 | ||
| 217 | if flags["tag"] then | 213 | if flags["tag"] then |
| 218 | if not version then | 214 | if not version then |
