From f0e18acab8ad686f8d8a57e1500110eade3491bd Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Thu, 1 Jun 2023 00:29:55 -0500 Subject: [PATCH] refactor: modify list parameters/add json output --- docs/svgs/viv-list-help.svg | 56 ++++++++++++++++++++----------------- src/viv/viv.py | 26 +++++++++++------ 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/docs/svgs/viv-list-help.svg b/docs/svgs/viv-list-help.svg index ffb4aea..db6400b 100644 --- a/docs/svgs/viv-list-help.svg +++ b/docs/svgs/viv-list-help.svg @@ -1,4 +1,4 @@ - + - - + + - + - + - + - + - + - + - + + + + - viv list --help + viv list --help - + - - usage: viv list [-h] [-v] [-q] - -list all vivenvs - -options: --h--help       show this help message and exit --v--verbose    show full metadata for vivenvs --q--quiet      suppress non-essential output + + usage: viv list [-h] [-f] [-q] [--json] + +list all vivenvs + +options: +-h--help     show this help message and exit +-f--full     show full metadata for vivenvs +-q--quiet    suppress non-essential output +--json         name:metadata json for vivenvs diff --git a/src/viv/viv.py b/src/viv/viv.py index 7a22508..c1dda33 100755 --- a/src/viv/viv.py +++ b/src/viv/viv.py @@ -746,20 +746,17 @@ class ViVenv: verbose=bool(os.getenv("VIV_VERBOSE")), ) - def show(self, verbose: bool = False) -> None: - if not verbose: - _id = ( + def show(self) -> None: + _id = ( self.meta.id[:8] if self.meta.id == self.name else (self.name[:5] + "..." if len(self.name) > 8 else self.name) ) - sys.stdout.write( + sys.stdout.write( f"""{a.bold}{a.cyan}{_id}{a.end} """ f"""{a.style(", ".join(self.meta.spec),'dim')}\n""" ) - else: - self.tree() def _tree_leaves(self, items: List[str], indent: str = "") -> str: tree_chars = ["├"] * (len(items) - 1) + ["╰"] @@ -999,9 +996,14 @@ class Viv: sys.stdout.write("\n".join(self.vivenvs) + "\n") elif len(self.vivenvs) == 0: echo("no vivenvs setup") + elif args.full: + for _, vivenv in self.vivenvs.items(): + vivenv.tree() + elif args.json: + sys.stdout.write(json.dumps({k:v.meta.__dict__ for k,v in self.vivenvs.items()})) else: for _, vivenv in self.vivenvs.items(): - vivenv.show(args.verbose) + vivenv.show() def exe(self, args: Namespace) -> None: """run python/pip in existing vivenv""" @@ -1292,8 +1294,8 @@ class Viv: p_list = self._get_subcmd_parser(subparsers, "list") p_list.add_argument( - "-v", - "--verbose", + "-f", + "--full", help="show full metadata for vivenvs", default=False, action="store_true", @@ -1305,6 +1307,12 @@ class Viv: action="store_true", default=False, ) + p_list.add_argument( + "--json", + help="name:metadata json for vivenvs ", + action="store_true", + default=False, + ) p_exe = self._get_subcmd_parser( subparsers,