aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2020-02-13 12:41:57 -0300
committerHisham Muhammad <hisham@gobolinux.org>2020-02-13 12:43:00 -0300
commit5620d3b00c7defcbcbcfcb2a42401a0f567ad30a (patch)
tree40788fd0b0476e9224ee353496f5f998c208528e /src
parenta7eba5be6c85d35bcca7c5cb4f9f923a0fa2a4d9 (diff)
downloadluarocks-5620d3b00c7defcbcbcfcb2a42401a0f567ad30a.tar.gz
luarocks-5620d3b00c7defcbcbcfcb2a42401a0f567ad30a.tar.bz2
luarocks-5620d3b00c7defcbcbcfcb2a42401a0f567ad30a.zip
show: accept a substring when unambiguous and matches a single entry
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/cmd/show.lua2
-rw-r--r--src/luarocks/search.lua20
2 files changed, 19 insertions, 3 deletions
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.
263function show.command(args) 263function 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
376end 392end
377 393
378return search 394return search