mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 12:03:31 +01:00
CmdGetAuthInfo: Code beautification
Fix clumsy code printing auth info. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
41cc712dee
commit
9d06e0bf2e
1 changed files with 14 additions and 9 deletions
|
|
@ -19,13 +19,15 @@ class CmdGetAuthInfo(Cmd): # export
|
||||||
parser.add_argument('--password', help='Show password', action='store_true', default=False)
|
parser.add_argument('--password', help='Show password', action='store_true', default=False)
|
||||||
|
|
||||||
def _run(self, args: Namespace) -> None:
|
def _run(self, args: Namespace) -> None:
|
||||||
|
keys = ['username', 'password']
|
||||||
|
|
||||||
|
# --- Milk jw-build repo
|
||||||
jw_build_dir = self.app.proj_dir('jw-build')
|
jw_build_dir = self.app.proj_dir('jw-build')
|
||||||
if not os.path.isdir(jw_build_dir + '/.git'):
|
if not os.path.isdir(jw_build_dir + '/.git'):
|
||||||
self.app.debug(f'jw-build directory is not a Git repo: {jw_build_dir}')
|
self.app.debug(f'jw-build directory is not a Git repo: {jw_build_dir}')
|
||||||
return
|
return
|
||||||
remotes = run_cmd(['git', '-C', jw_build_dir, 'remote', '-v'])
|
remotes = run_cmd(['git', '-C', jw_build_dir, 'remote', '-v'])
|
||||||
result: dict[str, str] = {}
|
result: dict[str, str] = {}
|
||||||
keys = ['username', 'password']
|
|
||||||
for line in remotes.split('\n'):
|
for line in remotes.split('\n'):
|
||||||
if re.match(r'^\s*$', line):
|
if re.match(r'^\s*$', line):
|
||||||
continue
|
continue
|
||||||
|
|
@ -35,11 +37,14 @@ class CmdGetAuthInfo(Cmd): # export
|
||||||
for key in keys:
|
for key in keys:
|
||||||
result[key] = getattr(parsed, key)
|
result[key] = getattr(parsed, key)
|
||||||
break
|
break
|
||||||
for key in keys:
|
|
||||||
if key in result and getattr(args, key, None) == True:
|
# --- Print results
|
||||||
if key is None:
|
for key, val in result.items():
|
||||||
continue
|
if getattr(args, key, None) != True:
|
||||||
if args.only_values:
|
continue
|
||||||
print(result[key])
|
if val is None:
|
||||||
continue
|
continue
|
||||||
print(f'{key}="{result[key]}"')
|
if args.only_values:
|
||||||
|
print(val)
|
||||||
|
continue
|
||||||
|
print(f'{key}="{val}"')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue