Allow using --show together with installing

--show now always lists programs installed in given location, possibly
after installing some.
This commit is contained in:
Peter Melnichenko 2018-08-18 11:38:11 +03:00
parent 0b33cd59fc
commit acd620b247

View File

@ -1977,6 +1977,21 @@ class UseActualArgsFileAction(argparse.Action):
main(args_content.split("\r\n")[1:]) main(args_content.split("\r\n")[1:])
def show_location():
if os.path.exists(opts.location):
all_identifiers = get_installed_identifiers()
if all_identifiers:
print("Programs installed in {}:".format(opts.location))
for program in [RioLua, LuaJIT, LuaRocks]:
if program.name in all_identifiers:
show_identifiers(all_identifiers[program.name])
else:
print("No programs installed in {}.".format(opts.location))
else:
print("{} does not exist.".format(opts.location))
def main(argv=None): def main(argv=None):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=hererocks_version + ", a tool for installing Lua and/or LuaRocks locally.", description=hererocks_version + ", a tool for installing Lua and/or LuaRocks locally.",
@ -2013,7 +2028,7 @@ def main(argv=None):
"Lua 5.3 is supported only since LuaRocks 2.2.0, and Lua 5.4 is supported only since " "Lua 5.3 is supported only since LuaRocks 2.2.0, and Lua 5.4 is supported only since "
"LuaRocks 3.0.0.") "LuaRocks 3.0.0.")
parser.add_argument("--show", default=False, action="store_true", parser.add_argument("--show", default=False, action="store_true",
help="Instead of installing show programs already present in <location>") help="Show programs installed in <location>, possibly after installing new ones.")
parser.add_argument("-i", "--ignore-installed", default=False, action="store_true", parser.add_argument("-i", "--ignore-installed", default=False, action="store_true",
help="Install even if requested version is already present.") help="Install even if requested version is already present.")
parser.add_argument( parser.add_argument(
@ -2080,26 +2095,7 @@ def main(argv=None):
if opts.lua and opts.luajit: if opts.lua and opts.luajit:
parser.error("can't install both PUC-Rio Lua and LuaJIT") parser.error("can't install both PUC-Rio Lua and LuaJIT")
if (opts.lua or opts.luajit or opts.luarocks) and opts.show: if opts.lua or opts.luajit or opts.luarocks:
parser.error("can't both install and show")
if opts.show:
if os.path.exists(opts.location):
all_identifiers = get_installed_identifiers()
if all_identifiers:
print("Programs installed in {}:".format(opts.location))
for program in [RioLua, LuaJIT, LuaRocks]:
if program.name in all_identifiers:
show_identifiers(all_identifiers[program.name])
else:
print("No programs installed in {}.".format(opts.location))
else:
print("Location does not exist.")
sys.exit(0)
global temp_dir global temp_dir
temp_dir = tempfile.mkdtemp() temp_dir = tempfile.mkdtemp()
@ -2148,6 +2144,10 @@ def main(argv=None):
remove_dir(temp_dir) remove_dir(temp_dir)
print("Done.") print("Done.")
if opts.show:
show_location()
sys.exit(0) sys.exit(0)
if __name__ == "__main__": if __name__ == "__main__":