mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 03:53:32 +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)
|
||||
|
||||
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}"')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue