feat: add system flag to viv manage show

This commit is contained in:
Daylin Morgan 2023-08-30 11:15:25 -05:00
parent f91d6eb4b4
commit 68a6f3155a
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -242,6 +242,10 @@ class Ansi:
) )
) )
def key_value(self, items: Dict[str, Any], indent: str = " ") -> None:
for k, v in items.items():
sys.stderr.write(f"{indent}{a.bold}{k}{a.end}: {v}\n")
def subprocess(self, command: List[str], output: str) -> None: def subprocess(self, command: List[str], output: str) -> None:
"""generate output for subprocess error """generate output for subprocess error
@ -504,24 +508,6 @@ if __name__ == "__main__":
""" """
@staticmethod
def show(
cli: Optional[Path | str], running: Path, local: Optional[Path | str]
) -> str:
return (
"\n".join(
f" {a.bold}{k}{a.end}: {v}"
for k, v in (
("Version", __version__),
("CLI", cli),
("Running Source", running),
("Local Source", local),
("Cache", Cfg().cache_base),
)
)
+ "\n"
)
# TODO: convert the below functions into a proper file/stream logging interface # TODO: convert the below functions into a proper file/stream logging interface
def echo( def echo(
@ -1563,6 +1549,7 @@ class Viv:
def cmd_manage_show( def cmd_manage_show(
self, self,
pythonpath: bool = False, pythonpath: bool = False,
system: bool = False,
) -> None: ) -> None:
"""manage viv itself""" """manage viv itself"""
if pythonpath: if pythonpath:
@ -1571,15 +1558,31 @@ class Viv:
else: else:
err_quit("expected to find a local installation") err_quit("expected to find a local installation")
else: else:
echo("Current:") echo(f"{a.yellow}Current{a.end}:")
sys.stderr.write( a.key_value(
self.t.show( {
cli=shutil.which("viv"), "Version": __version__,
running=self.running_source, "CLI": shutil.which("viv"),
local=self.local_source, "Running Source": self.running_source,
) "Local Source": self.local_source,
"Cache": Cfg().cache_base,
}
) )
if system:
import platform # noqa
echo(f"{a.yellow}System{a.end}:")
a.key_value(
{
"Python Exe": sys.executable,
"Python Version": platform.sys.version,
"Pip": subprocess_run(
["pip", "--version"], check_output=True
).strip(),
}
)
def cmd_manage_update( def cmd_manage_update(
self, self,
ref: str, ref: str,
@ -1941,7 +1944,8 @@ class Cli:
BoolArg( BoolArg(
flag="pythonpath", flag="pythonpath",
help="show the path/to/install", help="show the path/to/install",
) ),
BoolArg(flag="system", help="show system/python info too"),
], ],
("exe",): [ ("exe",): [
Arg( Arg(