refactor: autogenerate flags more

This commit is contained in:
Daylin Morgan 2023-08-07 19:18:18 -05:00
parent dadf4dacbf
commit c453b8f4bd
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -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-10-g7cedb07-dev" __version__ = "23.8a1-10-gdadf4da-dev"
class Spinner: class Spinner:
@ -1698,7 +1698,10 @@ class Viv:
class Arg: class Arg:
def __init__(self, *args: str, **kwargs: Any) -> None: def __init__(self, *args, flag: str = None, **kwargs: Any) -> None:
if flag:
self.args = [f"-{flag[0]}", f"--{flag}"]
else:
self.args = args self.args = args
self.kwargs = kwargs self.kwargs = kwargs
@ -1707,20 +1710,17 @@ class Cli:
args = { args = {
("list",): [ ("list",): [
Arg( Arg(
"-v", flag="verbose",
"--verbose",
help="pretty print full metadata for vivenvs", help="pretty print full metadata for vivenvs",
action="store_true", action="store_true",
), ),
Arg( Arg(
"-q", flag="quiet",
"--quiet",
help="show only ids", help="show only ids",
action="store_true", action="store_true",
), ),
Arg( Arg(
"-f", flag="filter",
"--filter",
help="filter vivenvs based on key:val", help="filter vivenvs based on key:val",
metavar="<key:value>", metavar="<key:value>",
action=KVAppendAction, action=KVAppendAction,
@ -1735,14 +1735,12 @@ class Cli:
], ],
("shim",): [ ("shim",): [
Arg( Arg(
"-f", flag="freeze",
"--freeze",
help="freeze/resolve all dependencies", help="freeze/resolve all dependencies",
action="store_true", action="store_true",
), ),
Arg( Arg(
"-o", flag="output",
"--output",
help="path/to/output file", help="path/to/output file",
type=Path, type=Path,
metavar="<path>", metavar="<path>",
@ -1750,15 +1748,12 @@ class Cli:
], ],
("cache_info",): [ ("cache_info",): [
Arg( Arg(
"-p", flag="path",
"--path",
help="print the absolute path to the vivenv", help="print the absolute path to the vivenv",
action="store_true", action="store_true",
), ),
], ],
("run",): [ ("run",): [Arg(flag="script", help="remote script to run", metavar="<script>")],
Arg("-s", "--script", help="remote script to run", metavar="<script>")
],
("exe", "cache_info"): [ ("exe", "cache_info"): [
Arg("vivenv_id", help="name/hash of vivenv", metavar="vivenv") Arg("vivenv_id", help="name/hash of vivenv", metavar="vivenv")
], ],
@ -1773,14 +1768,12 @@ class Cli:
], ],
("freeze", "shim"): [ ("freeze", "shim"): [
Arg( Arg(
"-p", flag="path",
"--path",
help="generate line to add viv to sys.path", help="generate line to add viv to sys.path",
choices=["abs", "rel"], choices=["abs", "rel"],
), ),
Arg( Arg(
"-s", flag="standalone",
"--standalone",
help="generate standalone activation function", help="generate standalone activation function",
action="store_true", action="store_true",
), ),
@ -1788,8 +1781,7 @@ class Cli:
("run", "freeze", "shim"): [ ("run", "freeze", "shim"): [
Arg("reqs", help="requirements specifiers", nargs="*"), Arg("reqs", help="requirements specifiers", nargs="*"),
Arg( Arg(
"-r", flag="requirements",
"--requirements",
help="path/to/requirements.txt file", help="path/to/requirements.txt file",
metavar="<path>", metavar="<path>",
type=Path, type=Path,
@ -1797,45 +1789,40 @@ class Cli:
], ],
("run", "freeze"): [ ("run", "freeze"): [
Arg( Arg(
"-k", flag="keep",
"--keep",
help="preserve environment", help="preserve environment",
action="store_true", action="store_true",
), ),
], ],
("run", "shim"): [ ("run", "shim"): [
Arg("-b", "--bin", help="console_script/script to invoke", metavar="<bin>"), Arg(flag="bin", help="console_script/script to invoke", metavar="<bin>"),
], ],
("manage_purge", "manage_update", "manage_install"): [ ("manage_purge", "manage_update", "manage_install"): [
Arg( Arg(
"-r", flag="ref",
"--ref",
help="git reference (branch/tag/commit)", help="git reference (branch/tag/commit)",
default="latest", default="latest",
metavar="<ref>", metavar="<ref>",
), ),
Arg( Arg(
"-s", flag="src",
"--src",
help="path/to/source_file", help="path/to/source_file",
default=Cfg().src, default=Cfg().src,
metavar="<src>", metavar="<src>",
), ),
Arg( Arg(
"-c", flag="cli",
"--cli",
help="path/to/cli (symlink to src)", help="path/to/cli (symlink to src)",
default=Path.home() / ".local" / "bin" / "viv", default=Path.home() / ".local" / "bin" / "viv",
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(flag="yes", help="respond yes to all prompts", action="store_true")
], ],
("manage_show",): [ ("manage_show",): [
Arg( Arg(
"-p", flag="pythonpath",
"--pythonpath",
help="show the path/to/install", help="show the path/to/install",
action="store_true", action="store_true",
) )