mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-12-22 10:40:44 -06:00
refactor: move remove/info under cache subcmd
This commit is contained in:
parent
2b7f97ecc5
commit
c75ae60c40
1 changed files with 40 additions and 29 deletions
|
@ -53,7 +53,7 @@ from typing import (
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
__version__ = "23.8a1-5-g4c782db-dev"
|
__version__ = "23.8a1-7-g8f6adcc-dev"
|
||||||
|
|
||||||
|
|
||||||
class Spinner:
|
class Spinner:
|
||||||
|
@ -1151,12 +1151,15 @@ class Viv:
|
||||||
else:
|
else:
|
||||||
err_quit(f"no matches found for {name_id}")
|
err_quit(f"no matches found for {name_id}")
|
||||||
|
|
||||||
def remove(self, vivenvs: List[str]) -> None:
|
def cache(self) -> None:
|
||||||
|
"""manage the viv vivenv cache"""
|
||||||
|
|
||||||
|
def cache_remove(self, vivenvs: List[str]) -> None:
|
||||||
"""\
|
"""\
|
||||||
remove a vivenv
|
remove a vivenv
|
||||||
|
|
||||||
To remove all viv venvs:
|
To remove all viv venvs:
|
||||||
`viv rm $(viv l -q)`
|
`viv cache remove $(viv l -q)`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for name in vivenvs:
|
for name in vivenvs:
|
||||||
|
@ -1241,7 +1244,7 @@ class Viv:
|
||||||
|
|
||||||
run(full_cmd, verbose=True)
|
run(full_cmd, verbose=True)
|
||||||
|
|
||||||
def info(self, vivenv_id: str, path: bool, use_json: bool) -> None:
|
def cache_info(self, vivenv_id: str, path: bool, use_json: bool) -> None:
|
||||||
"""get metadata about a vivenv"""
|
"""get metadata about a vivenv"""
|
||||||
vivenv = self._match_vivenv(vivenv_id)
|
vivenv = self._match_vivenv(vivenv_id)
|
||||||
metadata_file = vivenv.path / "vivmeta.json"
|
metadata_file = vivenv.path / "vivmeta.json"
|
||||||
|
@ -1578,7 +1581,7 @@ class Cli:
|
||||||
metavar="<path>",
|
metavar="<path>",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("info",): [
|
("cache_info",): [
|
||||||
Arg(
|
Arg(
|
||||||
"-p",
|
"-p",
|
||||||
"--path",
|
"--path",
|
||||||
|
@ -1586,16 +1589,13 @@ class Cli:
|
||||||
action="store_true",
|
action="store_true",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("remove",): [
|
|
||||||
Arg("vivenvs", help="name/hash of vivenv", nargs="*", metavar="vivenv")
|
|
||||||
],
|
|
||||||
("run",): [
|
("run",): [
|
||||||
Arg("-s", "--script", help="remote script to run", metavar="<script>")
|
Arg("-s", "--script", help="remote script to run", metavar="<script>")
|
||||||
],
|
],
|
||||||
("exe", "info"): [
|
("exe", "cache_info"): [
|
||||||
Arg("vivenv_id", help="name/hash of vivenv", metavar="vivenv")
|
Arg("vivenv_id", help="name/hash of vivenv", metavar="vivenv")
|
||||||
],
|
],
|
||||||
("list", "info"): [
|
("list", "cache_info"): [
|
||||||
Arg(
|
Arg(
|
||||||
"--json",
|
"--json",
|
||||||
help="name:metadata json for vivenvs ",
|
help="name:metadata json for vivenvs ",
|
||||||
|
@ -1639,7 +1639,7 @@ class Cli:
|
||||||
("run", "shim"): [
|
("run", "shim"): [
|
||||||
Arg("-b", "--bin", help="console_script/script to invoke", metavar="<bin>"),
|
Arg("-b", "--bin", help="console_script/script to invoke", metavar="<bin>"),
|
||||||
],
|
],
|
||||||
("manage|purge", "manage|update", "manage|install"): [
|
("manage_purge", "manage_update", "manage_install"): [
|
||||||
Arg(
|
Arg(
|
||||||
"-r",
|
"-r",
|
||||||
"--ref",
|
"--ref",
|
||||||
|
@ -1662,10 +1662,10 @@ class Cli:
|
||||||
metavar="<cli>",
|
metavar="<cli>",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("shim", "manage|purge", "manage|update", "manage|install"): [
|
("shim", "manage_purge", "manage_update", "manage_install"): [
|
||||||
Arg("-y", "--yes", help="respond yes to all prompts", action="store_true")
|
Arg("-y", "--yes", help="respond yes to all prompts", action="store_true")
|
||||||
],
|
],
|
||||||
("manage|show",): [
|
("manage_show",): [
|
||||||
Arg(
|
Arg(
|
||||||
"-p",
|
"-p",
|
||||||
"--pythonpath",
|
"--pythonpath",
|
||||||
|
@ -1679,6 +1679,9 @@ class Cli:
|
||||||
help="command to to execute",
|
help="command to to execute",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
("cache_remove",): [
|
||||||
|
Arg("vivenvs", help="name/hash of vivenv", nargs="*", metavar="vivenv")
|
||||||
|
],
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
cmds := dict.fromkeys(
|
cmds := dict.fromkeys(
|
||||||
|
@ -1687,24 +1690,36 @@ class Cli:
|
||||||
"shim",
|
"shim",
|
||||||
"run",
|
"run",
|
||||||
"exe",
|
"exe",
|
||||||
"remove",
|
"cache",
|
||||||
"freeze",
|
"freeze",
|
||||||
"info",
|
|
||||||
"manage",
|
"manage",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
).update(
|
).update(
|
||||||
{
|
{
|
||||||
"manage": {
|
cmd: {
|
||||||
subcmd: {"help": help, "aliases": [subcmd[0]]}
|
subcmd: {"help": help, "aliases": [subcmd[0]]}
|
||||||
for subcmd, help in (
|
for subcmd, help in subcmd_help
|
||||||
|
}
|
||||||
|
for cmd, subcmd_help in (
|
||||||
|
(
|
||||||
|
"cache",
|
||||||
|
(
|
||||||
|
("info", "get metadata about a vivenv"),
|
||||||
|
("remove", "remove a vivenv"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"manage",
|
||||||
|
(
|
||||||
("show", "show current installation"),
|
("show", "show current installation"),
|
||||||
("install", "install fresh viv"),
|
("install", "install fresh viv"),
|
||||||
("update", "update viv version"),
|
("update", "update viv version"),
|
||||||
("purge", "remove traces of viv"),
|
("purge", "remove traces of viv"),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, viv: Viv) -> None:
|
def __init__(self, viv: Viv) -> None:
|
||||||
|
@ -1778,7 +1793,7 @@ class Cli:
|
||||||
if not (args.reqs or args.script):
|
if not (args.reqs or args.script):
|
||||||
error("must specify a requirement or --script")
|
error("must specify a requirement or --script")
|
||||||
|
|
||||||
if name == "info":
|
if name == "cache_info":
|
||||||
if args.use_json and args.path:
|
if args.use_json and args.path:
|
||||||
error("--json and -p/--path are mutually exclusive")
|
error("--json and -p/--path are mutually exclusive")
|
||||||
|
|
||||||
|
@ -1789,10 +1804,6 @@ class Cli:
|
||||||
attr: Optional[str] = None,
|
attr: Optional[str] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> ArgumentParser:
|
) -> ArgumentParser:
|
||||||
# override for remove
|
|
||||||
if name == "remove":
|
|
||||||
aliases = ["rm"]
|
|
||||||
else:
|
|
||||||
aliases = kwargs.pop("aliases", [name[0]])
|
aliases = kwargs.pop("aliases", [name[0]])
|
||||||
|
|
||||||
cmd = getattr(self.viv, attr if attr else name)
|
cmd = getattr(self.viv, attr if attr else name)
|
||||||
|
@ -1830,7 +1841,7 @@ class Cli:
|
||||||
subcmd,
|
subcmd,
|
||||||
parents=[
|
parents=[
|
||||||
self.parsers[k]
|
self.parsers[k]
|
||||||
for k in self.cmd_arg_group_map[f"{cmd}|{subcmd}"]
|
for k in self.cmd_arg_group_map[f"{cmd}_{subcmd}"]
|
||||||
],
|
],
|
||||||
**kwargs,
|
**kwargs,
|
||||||
).set_defaults(func=getattr(self.viv, f"{cmd}_{subcmd}"))
|
).set_defaults(func=getattr(self.viv, f"{cmd}_{subcmd}"))
|
||||||
|
|
Loading…
Reference in a new issue