diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2020-02-13 12:41:57 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2020-02-13 12:43:00 -0300 |
commit | 5620d3b00c7defcbcbcfcb2a42401a0f567ad30a (patch) | |
tree | 40788fd0b0476e9224ee353496f5f998c208528e | |
parent | a7eba5be6c85d35bcca7c5cb4f9f923a0fa2a4d9 (diff) | |
download | luarocks-5620d3b00c7defcbcbcfcb2a42401a0f567ad30a.tar.gz luarocks-5620d3b00c7defcbcbcfcb2a42401a0f567ad30a.tar.bz2 luarocks-5620d3b00c7defcbcbcfcb2a42401a0f567ad30a.zip |
show: accept a substring when unambiguous and matches a single entry
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | spec/show_spec.lua | 11 | ||||
-rw-r--r-- | src/luarocks/cmd/show.lua | 2 | ||||
-rw-r--r-- | src/luarocks/search.lua | 20 |
4 files changed, 37 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 960ac47d..61c46ff2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md | |||
@@ -1,3 +1,10 @@ | |||
1 | ## What's new | ||
2 | |||
3 | ### Features | ||
4 | |||
5 | * The `show` command can now accept a substring of the rock's name, | ||
6 | like `list`. | ||
7 | |||
1 | ## What's new in LuaRocks 3.3.1 | 8 | ## What's new in LuaRocks 3.3.1 |
2 | 9 | ||
3 | This is a bugfix release: | 10 | This is a bugfix release: |
diff --git a/spec/show_spec.lua b/spec/show_spec.lua index a0987de0..c2840d29 100644 --- a/spec/show_spec.lua +++ b/spec/show_spec.lua | |||
@@ -78,6 +78,17 @@ describe("LuaRocks show #integration", function() | |||
78 | run.luarocks_bool("show luacov 0.13.0") | 78 | run.luarocks_bool("show luacov 0.13.0") |
79 | end) | 79 | end) |
80 | 80 | ||
81 | it("can find by substring", function() | ||
82 | assert(run.luarocks_bool("install has_build_dep --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) | ||
83 | assert.match("a_build_dep", run.luarocks("show has_")) | ||
84 | end) | ||
85 | |||
86 | it("fails when substring matches multiple", function() | ||
87 | assert(run.luarocks_bool("install has_build_dep --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) | ||
88 | assert(run.luarocks_bool("install a_build_dep --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) | ||
89 | assert.match("multiple installed packages match the name 'dep'", run.luarocks("show dep")) | ||
90 | end) | ||
91 | |||
81 | it("shows #build_dependencies", function() | 92 | it("shows #build_dependencies", function() |
82 | assert(run.luarocks_bool("install has_build_dep --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) | 93 | assert(run.luarocks_bool("install has_build_dep --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) |
83 | assert.match("a_build_dep", run.luarocks("show has_build_dep")) | 94 | assert.match("a_build_dep", run.luarocks("show has_build_dep")) |
diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua index 8bb61b94..6d8047d5 100644 --- a/src/luarocks/cmd/show.lua +++ b/src/luarocks/cmd/show.lua | |||
@@ -261,7 +261,7 @@ end | |||
261 | --- Driver function for "show" command. | 261 | --- Driver function for "show" command. |
262 | -- @return boolean: True if succeeded, nil on errors. | 262 | -- @return boolean: True if succeeded, nil on errors. |
263 | function show.command(args) | 263 | function show.command(args) |
264 | local query = queries.new(args.rock, args.namespace, args.version) | 264 | local query = queries.new(args.rock, args.namespace, args.version, true) |
265 | 265 | ||
266 | local name, version, repo, repo_url = search.pick_installed_rock(query, args.tree) | 266 | local name, version, repo, repo_url = search.pick_installed_rock(query, args.tree) |
267 | if not name then | 267 | if not name then |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 80e4caaa..99a969c1 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -361,9 +361,25 @@ function search.pick_installed_rock(query, given_tree) | |||
361 | return nil, "cannot find package "..tostring(query).."\nUse 'list' to find installed rocks." | 361 | return nil, "cannot find package "..tostring(query).."\nUse 'list' to find installed rocks." |
362 | end | 362 | end |
363 | 363 | ||
364 | if not result_tree[query.name] and next(result_tree, next(result_tree)) then | ||
365 | local out = { "multiple installed packages match the name '"..tostring(query).."':\n\n" } | ||
366 | for name, _ in util.sortedpairs(result_tree) do | ||
367 | table.insert(out, " " .. name .. "\n") | ||
368 | end | ||
369 | table.insert(out, "\nPlease specify a single rock.\n") | ||
370 | return nil, table.concat(out) | ||
371 | end | ||
372 | |||
364 | local version = nil | 373 | local version = nil |
365 | local repo_url | 374 | local repo_url |
366 | local _, versions = util.sortedpairs(result_tree)() | 375 | |
376 | local name, versions | ||
377 | if result_tree[query.name] then | ||
378 | name, versions = query.name, result_tree[query.name] | ||
379 | else | ||
380 | name, versions = util.sortedpairs(result_tree)() | ||
381 | end | ||
382 | |||
367 | --question: what do we do about multiple versions? This should | 383 | --question: what do we do about multiple versions? This should |
368 | --give us the latest version on the last repo (which is usually the global one) | 384 | --give us the latest version on the last repo (which is usually the global one) |
369 | for vs, repositories in util.sortedpairs(versions, vers.compare_versions) do | 385 | for vs, repositories in util.sortedpairs(versions, vers.compare_versions) do |
@@ -372,7 +388,7 @@ function search.pick_installed_rock(query, given_tree) | |||
372 | end | 388 | end |
373 | 389 | ||
374 | local repo = tree_map[repo_url] | 390 | local repo = tree_map[repo_url] |
375 | return query.name, version, repo, repo_url | 391 | return name, version, repo, repo_url |
376 | end | 392 | end |
377 | 393 | ||
378 | return search | 394 | return search |