-
Notifications
You must be signed in to change notification settings - Fork 10
/
cmds_envar.py
43 lines (36 loc) · 993 Bytes
/
cmds_envar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
from oldezpykitext.appkit import *
from oldezpykitext.yaml import EzYAML
ap = argparse.ArgumentParserWrapper()
an = ap.an
def main():
ap.parse()
ap.run()
@ap.sub('setuv')
@ap.arg('entry', nargs='*', help='name=value')
@ap.opt('f', 'file', nargs='*')
@ap.map('entry', files='file')
def set_user_vars(entries=None, files=None):
# print(entries, files)
entries = entries or []
files = files or []
envars = {}
for e in entries:
k, v = e.split('=', maxsplit=1)
envars[str(k)] = str(v)
# print(envars)
for fp in files:
y = EzYAML().set_file(fp).load()
for x in y.documents:
if isinstance(x, dict):
for k, v in x.items():
envars[str(k)] = str(v)
else:
continue
# print(envars)
os.EnVarKit.save(envars)
# print(envars)
for k, v in envars.items():
print(f'{k}={v}')
if __name__ == '__main__':
main()