Make it possible to have multiple contexts

main
Micke Nordin 5 months ago
parent 5433992395
commit 6c59202263

@ -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

@ -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):

@ -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",

Loading…
Cancel
Save