From 4c75d8c0e7dbd4436337755fbe5aa5b2f27073fd Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Thu, 17 Dec 2020 10:27:54 -0700 Subject: [PATCH] fix: table output and alias --- src/commands/force/user/display.ts | 38 ++++++++++++++++++++++++------ test/commands/user/display.test.ts | 5 +++- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/commands/force/user/display.ts b/src/commands/force/user/display.ts index c6c0c513..bb63e77c 100644 --- a/src/commands/force/user/display.ts +++ b/src/commands/force/user/display.ts @@ -82,20 +82,44 @@ export class UserDisplayCommand extends SfdxCommand { }; // if they passed in a alias and it maps to something we have an Alias. - const alias: string = await Aliases.fetch(this.flags.targetusername); - - if (alias) { - // they passed in an alias so we have that - result.alias = this.flags.targetusername; + const alias = await Aliases.create(Aliases.getDefaultOptions()); + const aliasContent = alias.getContents().orgs; + if (aliasContent) { + Object.keys(aliasContent).find((aliasedName) => { + result.alias = aliasContent[aliasedName]; + }); } if (userAuthData.password) { result.password = userAuthData.password; } - this.ux.styledHeader('User Description'); - this.ux.styledObject(result); + this.print(result); return result; } + + private print(result: Result): void { + const columns = { + columns: [ + { key: 'key', label: 'key' }, + { key: 'label', label: 'label' }, + ], + }; + + const tableRow = []; + // to get proper capitalization and spacing, enter the rows + tableRow.push({ key: 'Username', label: result.username }); + tableRow.push({ key: 'Profile Name', label: result.profileName }); + tableRow.push({ key: 'Id', label: result.id }); + tableRow.push({ key: 'Org Id', label: result.orgId }); + tableRow.push({ key: 'Access Token', label: result.accessToken }); + tableRow.push({ key: 'Instance Url', label: result.instanceUrl }); + tableRow.push({ key: 'Login Url', label: result.loginUrl }); + if (result.alias) tableRow.push({ key: 'Alias', label: result.alias }); + if (result.password) tableRow.push({ key: 'Password', label: result.password }); + + this.ux.styledHeader('User Description'); + this.ux.table(tableRow, columns); + } } diff --git a/test/commands/user/display.test.ts b/test/commands/user/display.test.ts index e9bffacc..d3c895c9 100644 --- a/test/commands/user/display.test.ts +++ b/test/commands/user/display.test.ts @@ -52,7 +52,10 @@ describe('force:user:display', () => { ]); } - stubMethod($$.SANDBOX, Aliases, 'fetch').resolves('testAlias'); + const alias = await Aliases.create(Aliases.getDefaultOptions()); + stubMethod($$.SANDBOX, Aliases, 'create').resolves(alias); + + stubMethod($$.SANDBOX, alias, 'getContents').returns({ orgs: { testAlias: 'testUser1@test.com' } }); } test