From 5620d3b00c7defcbcbcfcb2a42401a0f567ad30a Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 13 Feb 2020 12:41:57 -0300 Subject: show: accept a substring when unambiguous and matches a single entry --- src/luarocks/cmd/show.lua | 2 +- src/luarocks/search.lua | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src') 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 --- Driver function for "show" command. -- @return boolean: True if succeeded, nil on errors. function show.command(args) - local query = queries.new(args.rock, args.namespace, args.version) + local query = queries.new(args.rock, args.namespace, args.version, true) local name, version, repo, repo_url = search.pick_installed_rock(query, args.tree) 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) return nil, "cannot find package "..tostring(query).."\nUse 'list' to find installed rocks." end + if not result_tree[query.name] and next(result_tree, next(result_tree)) then + local out = { "multiple installed packages match the name '"..tostring(query).."':\n\n" } + for name, _ in util.sortedpairs(result_tree) do + table.insert(out, " " .. name .. "\n") + end + table.insert(out, "\nPlease specify a single rock.\n") + return nil, table.concat(out) + end + local version = nil local repo_url - local _, versions = util.sortedpairs(result_tree)() + + local name, versions + if result_tree[query.name] then + name, versions = query.name, result_tree[query.name] + else + name, versions = util.sortedpairs(result_tree)() + end + --question: what do we do about multiple versions? This should --give us the latest version on the last repo (which is usually the global one) for vs, repositories in util.sortedpairs(versions, vers.compare_versions) do @@ -372,7 +388,7 @@ function search.pick_installed_rock(query, given_tree) end local repo = tree_map[repo_url] - return query.name, version, repo, repo_url + return name, version, repo, repo_url end return search -- cgit v1.2.3-55-g6feb