CmdGetAuthInfo: Code beautification

Fix clumsy code printing auth info.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2025-11-20 10:26:16 +01:00
commit 9d06e0bf2e

View file

@ -19,13 +19,15 @@ class CmdGetAuthInfo(Cmd): # export
parser.add_argument('--password', help='Show password', action='store_true', default=False)
def _run(self, args: Namespace) -> None:
keys = ['username', 'password']
# --- Milk jw-build repo
jw_build_dir = self.app.proj_dir('jw-build')
if not os.path.isdir(jw_build_dir + '/.git'):
self.app.debug(f'jw-build directory is not a Git repo: {jw_build_dir}')
return
remotes = run_cmd(['git', '-C', jw_build_dir, 'remote', '-v'])
result: dict[str, str] = {}
keys = ['username', 'password']
for line in remotes.split('\n'):
if re.match(r'^\s*$', line):
continue
@ -35,11 +37,14 @@ class CmdGetAuthInfo(Cmd): # export
for key in keys:
result[key] = getattr(parsed, key)
break
for key in keys:
if key in result and getattr(args, key, None) == True:
if key is None:
continue
if args.only_values:
print(result[key])
continue
print(f'{key}="{result[key]}"')
# --- Print results
for key, val in result.items():
if getattr(args, key, None) != True:
continue
if val is None:
continue
if args.only_values:
print(val)
continue
print(f'{key}="{val}"')