mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-11-14 13:07:54 -06:00
refactor: more OOP less redundancy
This commit is contained in:
parent
6bf2ae4e83
commit
91d3fcdaf4
1 changed files with 30 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-11-gc453b8f-dev"
|
__version__ = "23.8a1-12-g6bf2ae4-dev"
|
||||||
|
|
||||||
|
|
||||||
class Spinner:
|
class Spinner:
|
||||||
|
@ -1708,18 +1708,26 @@ class Arg:
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
|
|
||||||
|
class BoolArg(Arg):
|
||||||
|
def __init__(self, *args, **kwargs: Any) -> None:
|
||||||
|
super(BoolArg, self).__init__(*args, action="store_true", **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class PathArg(Arg):
|
||||||
|
def __init__(self, *args, **kwargs: Any) -> None:
|
||||||
|
super(PathArg, self).__init__(*args, metavar="<path>", type=Path, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Cli:
|
class Cli:
|
||||||
args = {
|
args = {
|
||||||
("list",): [
|
("list",): [
|
||||||
Arg(
|
BoolArg(
|
||||||
flag="verbose",
|
flag="verbose",
|
||||||
help="pretty print full metadata for vivenvs",
|
help="pretty print full metadata for vivenvs",
|
||||||
action="store_true",
|
|
||||||
),
|
),
|
||||||
Arg(
|
BoolArg(
|
||||||
flag="quiet",
|
flag="quiet",
|
||||||
help="show only ids",
|
help="show only ids",
|
||||||
action="store_true",
|
|
||||||
),
|
),
|
||||||
Arg(
|
Arg(
|
||||||
flag="filter",
|
flag="filter",
|
||||||
|
@ -1736,34 +1744,34 @@ class Cli:
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("shim",): [
|
("shim",): [
|
||||||
Arg(
|
BoolArg(
|
||||||
flag="freeze",
|
flag="freeze",
|
||||||
help="freeze/resolve all dependencies",
|
help="freeze/resolve all dependencies",
|
||||||
action="store_true",
|
|
||||||
),
|
),
|
||||||
Arg(
|
PathArg(
|
||||||
flag="output",
|
flag="output",
|
||||||
help="path/to/output file",
|
help="path/to/output file",
|
||||||
type=Path,
|
|
||||||
metavar="<path>",
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("cache_info",): [
|
("cache_info",): [
|
||||||
Arg(
|
BoolArg(
|
||||||
flag="path",
|
flag="path",
|
||||||
help="print the absolute path to the vivenv",
|
help="print the absolute path to the vivenv",
|
||||||
action="store_true",
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("run",): [Arg(flag="script", help="remote script to run", metavar="<script>")],
|
("run",): [
|
||||||
|
PathArg(
|
||||||
|
flag="script",
|
||||||
|
help="remote script to run",
|
||||||
|
)
|
||||||
|
],
|
||||||
("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")
|
||||||
],
|
],
|
||||||
("list", "cache_info"): [
|
("list", "cache_info"): [
|
||||||
Arg(
|
BoolArg(
|
||||||
"--json",
|
"--json",
|
||||||
help="name:metadata json for vivenvs ",
|
help="name:metadata json for vivenvs ",
|
||||||
action="store_true",
|
|
||||||
default=False,
|
default=False,
|
||||||
dest="use_json",
|
dest="use_json",
|
||||||
)
|
)
|
||||||
|
@ -1774,26 +1782,22 @@ class Cli:
|
||||||
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(
|
BoolArg(
|
||||||
flag="standalone",
|
flag="standalone",
|
||||||
help="generate standalone activation function",
|
help="generate standalone activation function",
|
||||||
action="store_true",
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("run", "freeze", "shim"): [
|
("run", "freeze", "shim"): [
|
||||||
Arg("reqs", help="requirements specifiers", nargs="*"),
|
Arg("reqs", help="requirements specifiers", nargs="*"),
|
||||||
Arg(
|
PathArg(
|
||||||
flag="requirements",
|
flag="requirements",
|
||||||
help="path/to/requirements.txt file",
|
help="path/to/requirements.txt file",
|
||||||
metavar="<path>",
|
|
||||||
type=Path,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("run", "freeze"): [
|
("run", "freeze"): [
|
||||||
Arg(
|
BoolArg(
|
||||||
flag="keep",
|
flag="keep",
|
||||||
help="preserve environment",
|
help="preserve environment",
|
||||||
action="store_true",
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("run", "shim"): [
|
("run", "shim"): [
|
||||||
|
@ -1806,27 +1810,24 @@ class Cli:
|
||||||
default="latest",
|
default="latest",
|
||||||
metavar="<ref>",
|
metavar="<ref>",
|
||||||
),
|
),
|
||||||
Arg(
|
PathArg(
|
||||||
flag="src",
|
flag="src",
|
||||||
help="path/to/source_file",
|
help="path/to/source_file",
|
||||||
default=Cfg().src,
|
default=Cfg().src,
|
||||||
metavar="<src>",
|
|
||||||
),
|
),
|
||||||
Arg(
|
PathArg(
|
||||||
flag="cli",
|
flag="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>",
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
("shim", "manage_purge", "manage_update", "manage_install"): [
|
("shim", "manage_purge", "manage_update", "manage_install"): [
|
||||||
Arg(flag="yes", help="respond yes to all prompts", action="store_true")
|
BoolArg(flag="yes", help="respond yes to all prompts")
|
||||||
],
|
],
|
||||||
("manage_show",): [
|
("manage_show",): [
|
||||||
Arg(
|
BoolArg(
|
||||||
flag="pythonpath",
|
flag="pythonpath",
|
||||||
help="show the path/to/install",
|
help="show the path/to/install",
|
||||||
action="store_true",
|
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
("exe",): [
|
("exe",): [
|
||||||
|
|
Loading…
Reference in a new issue