Make it possible to have multiple contexts
This commit is contained in:
parent
5433992395
commit
6c59202263
3 changed files with 17 additions and 3 deletions
|
@ -70,10 +70,11 @@ options:
|
||||||
```
|
```
|
||||||
### CONFIG
|
### CONFIG
|
||||||
```
|
```
|
||||||
usage: knotctl config [-h] [-b BASEURL] [-p PASSWORD] [-u USERNAME]
|
usage: knotctl config [-h] [-c CONTEXT] [-b BASEURL] [-p PASSWORD] [-u USERNAME]
|
||||||
|
|
||||||
options:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
-c CONTEXT, --context CONTEXT
|
||||||
-b BASEURL, --baseurl BASEURL
|
-b BASEURL, --baseurl BASEURL
|
||||||
-p PASSWORD, --password PASSWORD
|
-p PASSWORD, --password PASSWORD
|
||||||
-u USERNAME, --username USERNAME
|
-u USERNAME, --username USERNAME
|
||||||
|
|
|
@ -87,12 +87,24 @@ def run_complete(shell: Union[None, str]):
|
||||||
|
|
||||||
def run_config(
|
def run_config(
|
||||||
config_filename: str,
|
config_filename: str,
|
||||||
|
context: Union[None, str] = None,
|
||||||
baseurl: Union[None, str] = None,
|
baseurl: Union[None, str] = None,
|
||||||
username: Union[None, str] = None,
|
username: Union[None, str] = None,
|
||||||
password: Union[None, str] = None,
|
password: Union[None, str] = None,
|
||||||
):
|
):
|
||||||
config = {"baseurl": baseurl, "username": username, "password": password}
|
config = {"baseurl": baseurl, "username": username, "password": password}
|
||||||
needed = []
|
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:
|
if not baseurl:
|
||||||
needed.append("baseurl")
|
needed.append("baseurl")
|
||||||
if not username:
|
if not username:
|
||||||
|
@ -245,6 +257,7 @@ def main() -> int:
|
||||||
|
|
||||||
configcmd = subparsers.add_parser("config")
|
configcmd = subparsers.add_parser("config")
|
||||||
configcmd.add_argument("-b", "--baseurl")
|
configcmd.add_argument("-b", "--baseurl")
|
||||||
|
configcmd.add_argument("-c", "--context")
|
||||||
configcmd.add_argument("-p", "--password")
|
configcmd.add_argument("-p", "--password")
|
||||||
configcmd.add_argument("-u", "--username")
|
configcmd.add_argument("-u", "--username")
|
||||||
|
|
||||||
|
@ -288,7 +301,7 @@ def main() -> int:
|
||||||
mkdir(config_basepath)
|
mkdir(config_basepath)
|
||||||
|
|
||||||
if args.command == "config":
|
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
|
return 0
|
||||||
|
|
||||||
if not isfile(config_filename):
|
if not isfile(config_filename):
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="knotctl",
|
name="knotctl",
|
||||||
version="0.0.6",
|
version="0.0.7",
|
||||||
packages=setuptools.find_packages(),
|
packages=setuptools.find_packages(),
|
||||||
author="Micke Nordin",
|
author="Micke Nordin",
|
||||||
author_email="hej@mic.ke",
|
author_email="hej@mic.ke",
|
||||||
|
|
Loading…
Add table
Reference in a new issue