From c453b8f4bd30cb7c76494be61f7eeb7b053d3f33 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 7 Aug 2023 19:18:18 -0500 Subject: [PATCH] refactor: autogenerate flags more --- src/viv/viv.py | 59 ++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/src/viv/viv.py b/src/viv/viv.py index eb0a1f8..a61b2c2 100755 --- a/src/viv/viv.py +++ b/src/viv/viv.py @@ -53,7 +53,7 @@ from typing import ( from urllib.error import HTTPError from urllib.request import urlopen -__version__ = "23.8a1-10-g7cedb07-dev" +__version__ = "23.8a1-10-gdadf4da-dev" class Spinner: @@ -1698,8 +1698,11 @@ class Viv: class Arg: - def __init__(self, *args: str, **kwargs: Any) -> None: - self.args = args + def __init__(self, *args, flag: str = None, **kwargs: Any) -> None: + if flag: + self.args = [f"-{flag[0]}", f"--{flag}"] + else: + self.args = args self.kwargs = kwargs @@ -1707,20 +1710,17 @@ class Cli: args = { ("list",): [ Arg( - "-v", - "--verbose", + flag="verbose", help="pretty print full metadata for vivenvs", action="store_true", ), Arg( - "-q", - "--quiet", + flag="quiet", help="show only ids", action="store_true", ), Arg( - "-f", - "--filter", + flag="filter", help="filter vivenvs based on key:val", metavar="", action=KVAppendAction, @@ -1735,14 +1735,12 @@ class Cli: ], ("shim",): [ Arg( - "-f", - "--freeze", + flag="freeze", help="freeze/resolve all dependencies", action="store_true", ), Arg( - "-o", - "--output", + flag="output", help="path/to/output file", type=Path, metavar="", @@ -1750,15 +1748,12 @@ class Cli: ], ("cache_info",): [ Arg( - "-p", - "--path", + flag="path", help="print the absolute path to the vivenv", action="store_true", ), ], - ("run",): [ - Arg("-s", "--script", help="remote script to run", metavar="