refactor: modify list parameters/add json output

This commit is contained in:
Daylin Morgan 2023-06-01 00:29:55 -05:00
parent e3284bee78
commit f0e18acab8
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
2 changed files with 47 additions and 35 deletions

View file

@ -1,4 +1,4 @@
<svg class="rich-terminal shadow" viewBox="0 0 890.3333333333334 277.5333333333333" xmlns="http://www.w3.org/2000/svg"> <svg class="rich-terminal shadow" viewBox="0 0 890.3333333333334 301.93333333333334" xmlns="http://www.w3.org/2000/svg">
<!-- Generated with Rich https://www.textualize.io & yartsu https://github.com/daylinmorgan/yartsu --> <!-- Generated with Rich https://www.textualize.io & yartsu https://github.com/daylinmorgan/yartsu -->
<style> <style>
@ -19,14 +19,14 @@
font-weight: 700; font-weight: 700;
} }
.terminal-3499396704-matrix { .terminal-1773455935-matrix {
font-family: Fira Code, monospace; font-family: Fira Code, monospace;
font-size: 20px; font-size: 20px;
line-height: 24.4px; line-height: 24.4px;
font-variant-east-asian: full-width; font-variant-east-asian: full-width;
} }
.terminal-3499396704-title { .terminal-1773455935-title {
font-size: 18px; font-size: 18px;
font-weight: bold; font-weight: bold;
font-family: arial; font-family: arial;
@ -36,56 +36,60 @@
-webkit-filter: drop-shadow( 2px 5px 2px rgba(0, 0, 0, .7)); -webkit-filter: drop-shadow( 2px 5px 2px rgba(0, 0, 0, .7));
filter: drop-shadow( 2px 5px 2px rgba(0, 0, 0, .7)); filter: drop-shadow( 2px 5px 2px rgba(0, 0, 0, .7));
} }
.terminal-3499396704-r1 { fill: #94e2d5;font-weight: bold } .terminal-1773455935-r1 { fill: #94e2d5;font-weight: bold }
.terminal-3499396704-r2 { fill: #c6d0f5 } .terminal-1773455935-r2 { fill: #c6d0f5 }
.terminal-3499396704-r3 { fill: #f9e2af;font-weight: bold } .terminal-1773455935-r3 { fill: #f9e2af;font-weight: bold }
</style> </style>
<defs> <defs>
<clipPath id="terminal-3499396704-clip-terminal"> <clipPath id="terminal-1773455935-clip-terminal">
<rect x="0" y="0" width="853.0" height="194.2" /> <rect x="0" y="0" width="853.0" height="218.6" />
</clipPath> </clipPath>
<clipPath id="terminal-3499396704-line-0"> <clipPath id="terminal-1773455935-line-0">
<rect x="0" y="1.5" width="854" height="24.65"/> <rect x="0" y="1.5" width="854" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-3499396704-line-1"> <clipPath id="terminal-1773455935-line-1">
<rect x="0" y="25.9" width="854" height="24.65"/> <rect x="0" y="25.9" width="854" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-3499396704-line-2"> <clipPath id="terminal-1773455935-line-2">
<rect x="0" y="50.3" width="854" height="24.65"/> <rect x="0" y="50.3" width="854" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-3499396704-line-3"> <clipPath id="terminal-1773455935-line-3">
<rect x="0" y="74.7" width="854" height="24.65"/> <rect x="0" y="74.7" width="854" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-3499396704-line-4"> <clipPath id="terminal-1773455935-line-4">
<rect x="0" y="99.1" width="854" height="24.65"/> <rect x="0" y="99.1" width="854" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-3499396704-line-5"> <clipPath id="terminal-1773455935-line-5">
<rect x="0" y="123.5" width="854" height="24.65"/> <rect x="0" y="123.5" width="854" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-3499396704-line-6"> <clipPath id="terminal-1773455935-line-6">
<rect x="0" y="147.9" width="854" height="24.65"/> <rect x="0" y="147.9" width="854" height="24.65"/>
</clipPath> </clipPath>
<clipPath id="terminal-1773455935-line-7">
<rect x="0" y="172.3" width="854" height="24.65"/>
</clipPath>
</defs> </defs>
<rect fill="#1e1e2e" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="10.1667" y="1" width="870" height="243.2" rx="8"/><text class="terminal-3499396704-title" fill="#c6d0f5" text-anchor="middle" x="435" y="27">viv&#160;list&#160;--help</text> <rect fill="#1e1e2e" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="10.1667" y="1" width="870" height="267.6" rx="8"/><text class="terminal-1773455935-title" fill="#c6d0f5" text-anchor="middle" x="435" y="27">viv&#160;list&#160;--help</text>
<g transform="translate(32,22)"> <g transform="translate(32,22)">
<circle cx="0" cy="0" r="7" fill="#ff5f57"/> <circle cx="0" cy="0" r="7" fill="#ff5f57"/>
<circle cx="22" cy="0" r="7" fill="#febc2e"/> <circle cx="22" cy="0" r="7" fill="#febc2e"/>
<circle cx="44" cy="0" r="7" fill="#28c840"/> <circle cx="44" cy="0" r="7" fill="#28c840"/>
</g> </g>
<g transform="translate(18.166666666666664, 41) scale(.95)" clip-path="url(#terminal-3499396704-clip-terminal)"> <g transform="translate(18.166666666666664, 41) scale(.95)" clip-path="url(#terminal-1773455935-clip-terminal)">
<g class="terminal-3499396704-matrix"> <g class="terminal-1773455935-matrix">
<text class="terminal-3499396704-r1" x="0" y="20" textLength="61" clip-path="url(#terminal-3499396704-line-0)">usage</text><text class="terminal-3499396704-r2" x="61" y="20" textLength="305" clip-path="url(#terminal-3499396704-line-0)">:&#160;viv&#160;list&#160;[-h]&#160;[-v]&#160;[-q]</text><text class="terminal-3499396704-r2" x="854" y="20" textLength="12.2" clip-path="url(#terminal-3499396704-line-0)"> <text class="terminal-1773455935-r1" x="0" y="20" textLength="61" clip-path="url(#terminal-1773455935-line-0)">usage</text><text class="terminal-1773455935-r2" x="61" y="20" textLength="414.8" clip-path="url(#terminal-1773455935-line-0)">:&#160;viv&#160;list&#160;[-h]&#160;[-f]&#160;[-q]&#160;[--json]</text><text class="terminal-1773455935-r2" x="854" y="20" textLength="12.2" clip-path="url(#terminal-1773455935-line-0)">
</text><text class="terminal-3499396704-r2" x="854" y="44.4" textLength="12.2" clip-path="url(#terminal-3499396704-line-1)"> </text><text class="terminal-1773455935-r2" x="854" y="44.4" textLength="12.2" clip-path="url(#terminal-1773455935-line-1)">
</text><text class="terminal-3499396704-r2" x="0" y="68.8" textLength="195.2" clip-path="url(#terminal-3499396704-line-2)">list&#160;all&#160;vivenvs</text><text class="terminal-3499396704-r2" x="854" y="68.8" textLength="12.2" clip-path="url(#terminal-3499396704-line-2)"> </text><text class="terminal-1773455935-r2" x="0" y="68.8" textLength="195.2" clip-path="url(#terminal-1773455935-line-2)">list&#160;all&#160;vivenvs</text><text class="terminal-1773455935-r2" x="854" y="68.8" textLength="12.2" clip-path="url(#terminal-1773455935-line-2)">
</text><text class="terminal-3499396704-r2" x="854" y="93.2" textLength="12.2" clip-path="url(#terminal-3499396704-line-3)"> </text><text class="terminal-1773455935-r2" x="854" y="93.2" textLength="12.2" clip-path="url(#terminal-1773455935-line-3)">
</text><text class="terminal-3499396704-r1" x="0" y="117.6" textLength="85.4" clip-path="url(#terminal-3499396704-line-4)">options</text><text class="terminal-3499396704-r2" x="85.4" y="117.6" textLength="12.2" clip-path="url(#terminal-3499396704-line-4)">:</text><text class="terminal-3499396704-r2" x="854" y="117.6" textLength="12.2" clip-path="url(#terminal-3499396704-line-4)"> </text><text class="terminal-1773455935-r1" x="0" y="117.6" textLength="85.4" clip-path="url(#terminal-1773455935-line-4)">options</text><text class="terminal-1773455935-r2" x="85.4" y="117.6" textLength="12.2" clip-path="url(#terminal-1773455935-line-4)">:</text><text class="terminal-1773455935-r2" x="854" y="117.6" textLength="12.2" clip-path="url(#terminal-1773455935-line-4)">
</text><text class="terminal-3499396704-r3" x="24.4" y="142" textLength="24.4" clip-path="url(#terminal-3499396704-line-5)">-h</text><text class="terminal-3499396704-r2" x="48.8" y="142" textLength="24.4" clip-path="url(#terminal-3499396704-line-5)">,&#160;</text><text class="terminal-3499396704-r3" x="73.2" y="142" textLength="73.2" clip-path="url(#terminal-3499396704-line-5)">--help</text><text class="terminal-3499396704-r2" x="146.4" y="142" textLength="463.6" clip-path="url(#terminal-3499396704-line-5)">&#160;&#160;&#160;&#160;&#160;&#160;&#160;show&#160;this&#160;help&#160;message&#160;and&#160;exit</text><text class="terminal-3499396704-r2" x="854" y="142" textLength="12.2" clip-path="url(#terminal-3499396704-line-5)"> </text><text class="terminal-1773455935-r3" x="24.4" y="142" textLength="24.4" clip-path="url(#terminal-1773455935-line-5)">-h</text><text class="terminal-1773455935-r2" x="48.8" y="142" textLength="24.4" clip-path="url(#terminal-1773455935-line-5)">,&#160;</text><text class="terminal-1773455935-r3" x="73.2" y="142" textLength="73.2" clip-path="url(#terminal-1773455935-line-5)">--help</text><text class="terminal-1773455935-r2" x="146.4" y="142" textLength="439.2" clip-path="url(#terminal-1773455935-line-5)">&#160;&#160;&#160;&#160;&#160;show&#160;this&#160;help&#160;message&#160;and&#160;exit</text><text class="terminal-1773455935-r2" x="854" y="142" textLength="12.2" clip-path="url(#terminal-1773455935-line-5)">
</text><text class="terminal-3499396704-r3" x="24.4" y="166.4" textLength="24.4" clip-path="url(#terminal-3499396704-line-6)">-v</text><text class="terminal-3499396704-r2" x="48.8" y="166.4" textLength="24.4" clip-path="url(#terminal-3499396704-line-6)">,&#160;</text><text class="terminal-3499396704-r3" x="73.2" y="166.4" textLength="109.8" clip-path="url(#terminal-3499396704-line-6)">--verbose</text><text class="terminal-3499396704-r2" x="183" y="166.4" textLength="414.8" clip-path="url(#terminal-3499396704-line-6)">&#160;&#160;&#160;&#160;show&#160;full&#160;metadata&#160;for&#160;vivenvs</text><text class="terminal-3499396704-r2" x="854" y="166.4" textLength="12.2" clip-path="url(#terminal-3499396704-line-6)"> </text><text class="terminal-1773455935-r3" x="24.4" y="166.4" textLength="24.4" clip-path="url(#terminal-1773455935-line-6)">-f</text><text class="terminal-1773455935-r2" x="48.8" y="166.4" textLength="24.4" clip-path="url(#terminal-1773455935-line-6)">,&#160;</text><text class="terminal-1773455935-r3" x="73.2" y="166.4" textLength="73.2" clip-path="url(#terminal-1773455935-line-6)">--full</text><text class="terminal-1773455935-r2" x="146.4" y="166.4" textLength="427" clip-path="url(#terminal-1773455935-line-6)">&#160;&#160;&#160;&#160;&#160;show&#160;full&#160;metadata&#160;for&#160;vivenvs</text><text class="terminal-1773455935-r2" x="854" y="166.4" textLength="12.2" clip-path="url(#terminal-1773455935-line-6)">
</text><text class="terminal-3499396704-r3" x="24.4" y="190.8" textLength="24.4" clip-path="url(#terminal-3499396704-line-7)">-q</text><text class="terminal-3499396704-r2" x="48.8" y="190.8" textLength="24.4" clip-path="url(#terminal-3499396704-line-7)">,&#160;</text><text class="terminal-3499396704-r3" x="73.2" y="190.8" textLength="85.4" clip-path="url(#terminal-3499396704-line-7)">--quiet</text><text class="terminal-3499396704-r2" x="158.6" y="190.8" textLength="427" clip-path="url(#terminal-3499396704-line-7)">&#160;&#160;&#160;&#160;&#160;&#160;suppress&#160;non-essential&#160;output</text><text class="terminal-3499396704-r2" x="854" y="190.8" textLength="12.2" clip-path="url(#terminal-3499396704-line-7)"> </text><text class="terminal-1773455935-r3" x="24.4" y="190.8" textLength="24.4" clip-path="url(#terminal-1773455935-line-7)">-q</text><text class="terminal-1773455935-r2" x="48.8" y="190.8" textLength="24.4" clip-path="url(#terminal-1773455935-line-7)">,&#160;</text><text class="terminal-1773455935-r3" x="73.2" y="190.8" textLength="85.4" clip-path="url(#terminal-1773455935-line-7)">--quiet</text><text class="terminal-1773455935-r2" x="158.6" y="190.8" textLength="402.6" clip-path="url(#terminal-1773455935-line-7)">&#160;&#160;&#160;&#160;suppress&#160;non-essential&#160;output</text><text class="terminal-1773455935-r2" x="854" y="190.8" textLength="12.2" clip-path="url(#terminal-1773455935-line-7)">
</text><text class="terminal-1773455935-r3" x="24.4" y="215.2" textLength="73.2" clip-path="url(#terminal-1773455935-line-8)">--json</text><text class="terminal-1773455935-r2" x="97.6" y="215.2" textLength="475.8" clip-path="url(#terminal-1773455935-line-8)">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;name:metadata&#160;json&#160;for&#160;vivenvs</text><text class="terminal-1773455935-r2" x="854" y="215.2" textLength="12.2" clip-path="url(#terminal-1773455935-line-8)">
</text> </text>
</g> </g>
</g> </g>

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View file

@ -746,20 +746,17 @@ class ViVenv:
verbose=bool(os.getenv("VIV_VERBOSE")), verbose=bool(os.getenv("VIV_VERBOSE")),
) )
def show(self, verbose: bool = False) -> None: def show(self) -> None:
if not verbose: _id = (
_id = (
self.meta.id[:8] self.meta.id[:8]
if self.meta.id == self.name if self.meta.id == self.name
else (self.name[:5] + "..." if len(self.name) > 8 else 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.bold}{a.cyan}{_id}{a.end} """
f"""{a.style(", ".join(self.meta.spec),'dim')}\n""" f"""{a.style(", ".join(self.meta.spec),'dim')}\n"""
) )
else:
self.tree()
def _tree_leaves(self, items: List[str], indent: str = "") -> str: def _tree_leaves(self, items: List[str], indent: str = "") -> str:
tree_chars = [""] * (len(items) - 1) + [""] tree_chars = [""] * (len(items) - 1) + [""]
@ -999,9 +996,14 @@ class Viv:
sys.stdout.write("\n".join(self.vivenvs) + "\n") sys.stdout.write("\n".join(self.vivenvs) + "\n")
elif len(self.vivenvs) == 0: elif len(self.vivenvs) == 0:
echo("no vivenvs setup") 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: else:
for _, vivenv in self.vivenvs.items(): for _, vivenv in self.vivenvs.items():
vivenv.show(args.verbose) vivenv.show()
def exe(self, args: Namespace) -> None: def exe(self, args: Namespace) -> None:
"""run python/pip in existing vivenv""" """run python/pip in existing vivenv"""
@ -1292,8 +1294,8 @@ class Viv:
p_list = self._get_subcmd_parser(subparsers, "list") p_list = self._get_subcmd_parser(subparsers, "list")
p_list.add_argument( p_list.add_argument(
"-v", "-f",
"--verbose", "--full",
help="show full metadata for vivenvs", help="show full metadata for vivenvs",
default=False, default=False,
action="store_true", action="store_true",
@ -1305,6 +1307,12 @@ class Viv:
action="store_true", action="store_true",
default=False, default=False,
) )
p_list.add_argument(
"--json",
help="name:metadata json for vivenvs ",
action="store_true",
default=False,
)
p_exe = self._get_subcmd_parser( p_exe = self._get_subcmd_parser(
subparsers, subparsers,