mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-11-14 13:07:54 -06:00
refactor: consolidate cli commands
This commit is contained in:
parent
d71542f5d2
commit
0e262cc0f9
1 changed files with 15 additions and 14 deletions
|
@ -1388,10 +1388,10 @@ class Viv:
|
||||||
else:
|
else:
|
||||||
err_quit(f"no matches found for {name_id}")
|
err_quit(f"no matches found for {name_id}")
|
||||||
|
|
||||||
def cmd_cache(self) -> None:
|
def cmd_env(self) -> None:
|
||||||
"""manage the viv vivenv cache"""
|
"""manage the viv vivenv cache"""
|
||||||
|
|
||||||
def cmd_cache_remove(self, vivenvs: List[str]) -> None:
|
def cmd_env_remove(self, vivenvs: List[str]) -> None:
|
||||||
"""\
|
"""\
|
||||||
remove a vivenv
|
remove a vivenv
|
||||||
|
|
||||||
|
@ -1489,7 +1489,7 @@ class Viv:
|
||||||
for vivenv in vivenvs:
|
for vivenv in vivenvs:
|
||||||
vivenv.show(size_pad)
|
vivenv.show(size_pad)
|
||||||
|
|
||||||
def cmd_exe(self, vivenv_id: str, cmd: str, rest: List[str]) -> None:
|
def cmd_env_exe(self, vivenv_id: str, cmd: str, rest: List[str]) -> None:
|
||||||
"""\
|
"""\
|
||||||
run binary/script in existing vivenv
|
run binary/script in existing vivenv
|
||||||
|
|
||||||
|
@ -1508,7 +1508,7 @@ class Viv:
|
||||||
# TODO: use subprocess_run_quit
|
# TODO: use subprocess_run_quit
|
||||||
subprocess_run(full_cmd, verbose=True)
|
subprocess_run(full_cmd, verbose=True)
|
||||||
|
|
||||||
def cmd_cache_info(
|
def cmd_env_info(
|
||||||
self, vivenv_id: str, path: bool, use_json: bool, size: bool
|
self, vivenv_id: str, path: bool, use_json: bool, size: bool
|
||||||
) -> None:
|
) -> None:
|
||||||
"""get metadata about a vivenv"""
|
"""get metadata about a vivenv"""
|
||||||
|
@ -1886,17 +1886,17 @@ class Cli:
|
||||||
help="path/to/output file",
|
help="path/to/output file",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("cache_info",): [
|
("env_info",): [
|
||||||
BoolArg(
|
BoolArg(
|
||||||
flag="path",
|
flag="path",
|
||||||
help="print the absolute path to the vivenv",
|
help="print the absolute path to the vivenv",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("run",): [Arg(flag="script", help="script to execute", metavar="<path/url>")],
|
("run",): [Arg(flag="script", help="script to execute", metavar="<path/url>")],
|
||||||
("exe", "cache_info"): [
|
("env_exe", "env_info"): [
|
||||||
Arg("vivenv_id", help="name/hash of vivenv", metavar="vivenv")
|
Arg("vivenv_id", help="name/hash of vivenv", metavar="vivenv")
|
||||||
],
|
],
|
||||||
("list", "cache_info"): [
|
("list", "env_info"): [
|
||||||
BoolArg(flag="size", help="calculate size of vivenvs"),
|
BoolArg(flag="size", help="calculate size of vivenvs"),
|
||||||
BoolArg(
|
BoolArg(
|
||||||
"--json",
|
"--json",
|
||||||
|
@ -1960,13 +1960,13 @@ class Cli:
|
||||||
),
|
),
|
||||||
BoolArg(flag="system", help="show system/python info too"),
|
BoolArg(flag="system", help="show system/python info too"),
|
||||||
],
|
],
|
||||||
("exe",): [
|
("env_exe",): [
|
||||||
Arg(
|
Arg(
|
||||||
"cmd",
|
"cmd",
|
||||||
help="command to to execute",
|
help="command to to execute",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
("cache_remove",): [
|
("env_remove",): [
|
||||||
Arg("vivenvs", help="name/hash of vivenv", nargs="*", metavar="vivenv")
|
Arg("vivenvs", help="name/hash of vivenv", nargs="*", metavar="vivenv")
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
@ -1976,8 +1976,8 @@ class Cli:
|
||||||
"list",
|
"list",
|
||||||
"shim",
|
"shim",
|
||||||
"run",
|
"run",
|
||||||
"exe",
|
# "exe",
|
||||||
"cache",
|
"env",
|
||||||
"freeze",
|
"freeze",
|
||||||
"manage",
|
"manage",
|
||||||
)
|
)
|
||||||
|
@ -1990,8 +1990,9 @@ class Cli:
|
||||||
}
|
}
|
||||||
for cmd, subcmd_help in (
|
for cmd, subcmd_help in (
|
||||||
(
|
(
|
||||||
"cache",
|
"env",
|
||||||
(
|
(
|
||||||
|
("exe", "run binary/script in existing vivenv"),
|
||||||
("info", "get metadata about a vivenv"),
|
("info", "get metadata about a vivenv"),
|
||||||
("remove", "remove a vivenv"),
|
("remove", "remove a vivenv"),
|
||||||
),
|
),
|
||||||
|
@ -2080,7 +2081,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 == "cache_info":
|
if name == "env_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")
|
||||||
|
|
||||||
|
@ -2154,7 +2155,7 @@ class Cli:
|
||||||
args.rest = sys.argv[i + 2 :]
|
args.rest = sys.argv[i + 2 :]
|
||||||
else:
|
else:
|
||||||
args = self.parser.parse_args()
|
args = self.parser.parse_args()
|
||||||
if args.func.__name__ in ("cmd_run", "cmd_exe"):
|
if args.func.__name__ in ("cmd_run", "cmd_env_exe"):
|
||||||
args.rest = []
|
args.rest = []
|
||||||
|
|
||||||
self._validate_args(args)
|
self._validate_args(args)
|
||||||
|
|
Loading…
Reference in a new issue