From 6c59202263faf49817fe4b99b44b7b2080f6cf8d Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Mon, 24 Jun 2024 16:03:36 +0200 Subject: [PATCH] Make it possible to have multiple contexts --- README.md | 3 ++- scripts/knotctl | 15 ++++++++++++++- setup.py | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9ff649e..33dc3d2 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,11 @@ options: ``` ### CONFIG ``` -usage: knotctl config [-h] [-b BASEURL] [-p PASSWORD] [-u USERNAME] +usage: knotctl config [-h] [-c CONTEXT] [-b BASEURL] [-p PASSWORD] [-u USERNAME] options: -h, --help show this help message and exit + -c CONTEXT, --context CONTEXT -b BASEURL, --baseurl BASEURL -p PASSWORD, --password PASSWORD -u USERNAME, --username USERNAME diff --git a/scripts/knotctl b/scripts/knotctl index 271fb3b..cc66dca 100755 --- a/scripts/knotctl +++ b/scripts/knotctl @@ -87,12 +87,24 @@ def run_complete(shell: Union[None, str]): def run_config( config_filename: str, + context: Union[None, str] = None, baseurl: Union[None, str] = None, username: Union[None, str] = None, password: Union[None, str] = None, ): config = {"baseurl": baseurl, "username": username, "password": password} needed = [] + if context: + symlink = f'{config_filename}-{context}' + found = os.path.isfile(symlink) + if os.path.islink(config_filename): + os.remove(config_filename) + elif os.path.isfile(config_filename): + os.rename(config_filename, symlink) + os.symlink(symlink, config_filename) + config_filename = symlink + if found: + return if not baseurl: needed.append("baseurl") if not username: @@ -245,6 +257,7 @@ def main() -> int: configcmd = subparsers.add_parser("config") configcmd.add_argument("-b", "--baseurl") + configcmd.add_argument("-c", "--context") configcmd.add_argument("-p", "--password") configcmd.add_argument("-u", "--username") @@ -288,7 +301,7 @@ def main() -> int: mkdir(config_basepath) if args.command == "config": - run_config(config_filename, args.baseurl, args.username, args.password) + run_config(config_filename, args.context, args.baseurl, args.username, args.password) return 0 if not isfile(config_filename): diff --git a/setup.py b/setup.py index 4490ed3..e5968ba 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh: setuptools.setup( name="knotctl", - version="0.0.6", + version="0.0.7", packages=setuptools.find_packages(), author="Micke Nordin", author_email="hej@mic.ke",