Skip to content

Commit 598c170

Browse files
committed
list/info sub-commands can refresh the cache now; outputting help now if no sub-command chosen
1 parent 9925ce9 commit 598c170

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

python/weka/core/packages.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,8 @@ def _subcmd_list(args):
676676
"""
677677
Lists packages (name and version).
678678
"""
679+
if args.refresh_cache:
680+
refresh_cache()
679681
if args.type == "all":
680682
pkgs = all_packages()
681683
elif args.type == "installed":
@@ -691,6 +693,8 @@ def _subcmd_info(args):
691693
"""
692694
Outputs information for packages.
693695
"""
696+
if args.refresh_cache:
697+
refresh_cache()
694698
pkgs = [all_package(x).as_dict() for x in args.name]
695699
_output_pkg_info(pkgs, args)
696700

@@ -774,6 +778,7 @@ def main(args=None):
774778
parser.add_argument("type", nargs="?", choices=["all", "installed", "available"], default="all", help="defines what packages to list")
775779
parser.add_argument("-f", "--format", choices=["text", "json"], default="text", help="the output format to use")
776780
parser.add_argument("-o", "--output", metavar="FILE", default=None, help="the file to store the output in, uses stdout if not supplied")
781+
parser.add_argument("-r", "--refresh-cache", dest="refresh_cache", action="store_true", help="whether to refresh the package cache")
777782
parser.set_defaults(func=_subcmd_list)
778783

779784
# info
@@ -782,6 +787,7 @@ def main(args=None):
782787
parser.add_argument("-t", "--type", choices=["brief", "full"], default="brief", help="the type of information to output")
783788
parser.add_argument("-f", "--format", choices=["text", "json"], default="text", help="the output format to use")
784789
parser.add_argument("-o", "--output", metavar="FILE", default=None, help="the file to store the output in, uses stdout if not supplied")
790+
parser.add_argument("-r", "--refresh-cache", dest="refresh_cache", action="store_true", help="whether to refresh the package cache")
785791
parser.set_defaults(func=_subcmd_info)
786792

787793
# install
@@ -810,15 +816,18 @@ def main(args=None):
810816
parser.set_defaults(func=_subcmd_is_installed)
811817

812818
parsed = main_parser.parse_args(args=args)
813-
814-
# execute action
815-
jvm.start(packages=True)
816-
try:
817-
parsed.func(parsed)
818-
except Exception:
819-
print(traceback.format_exc())
820-
finally:
821-
jvm.stop()
819+
# no action chosen? show help
820+
if not hasattr(parsed, "func"):
821+
main_parser.print_help()
822+
else:
823+
# execute action
824+
jvm.start(packages=True)
825+
try:
826+
parsed.func(parsed)
827+
except Exception:
828+
print(traceback.format_exc())
829+
finally:
830+
jvm.stop()
822831

823832

824833
def sys_main():

0 commit comments

Comments
 (0)