-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3eebc41
commit 362d546
Showing
4 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Argv, ArgumentsCamelCase, CommandModule } from 'yargs'; | ||
import { logger } from '@hubspot/local-dev-lib/logger'; | ||
import { getAccountConfig } from '@hubspot/local-dev-lib/config'; | ||
import { getAccessToken } from '@hubspot/local-dev-lib/personalAccessKey'; | ||
import { addConfigOptions } from '../../lib/commonOpts'; | ||
import { i18n } from '../../lib/lang'; | ||
import { getTableContents } from '../../lib/ui/table'; | ||
import { CommonArgs, ConfigOptions } from '../../types/Yargs'; | ||
|
||
const i18nKey = 'commands.account.subcommands.info'; | ||
|
||
type AccountInfoArgs = CommonArgs & ConfigOptions; | ||
|
||
class AccountInfo implements CommandModule<CommonArgs, AccountInfoArgs> { | ||
public command = 'info [account]'; | ||
public describe = i18n(`${i18nKey}.describe`); | ||
|
||
public builder(yargs: Argv): Argv<AccountInfoArgs> { | ||
addConfigOptions(yargs); | ||
|
||
yargs.example([ | ||
['$0 accounts info', i18n(`${i18nKey}.examples.default`)], | ||
['$0 accounts info MyAccount', i18n(`${i18nKey}.examples.nameBased`)], | ||
['$0 accounts info 1234567', i18n(`${i18nKey}.examples.idBased`)], | ||
]); | ||
|
||
return yargs as Argv<AccountInfoArgs>; | ||
} | ||
|
||
public async handler( | ||
args: ArgumentsCamelCase<AccountInfoArgs> | ||
): Promise<void> { | ||
const { derivedAccountId } = args; | ||
const config = getAccountConfig(derivedAccountId); | ||
// check if the provided account is using a personal access key, if not, show an error | ||
if (config && config.authType === 'personalaccesskey') { | ||
const { name, personalAccessKey, env } = config; | ||
let scopeGroups: string[][] = []; | ||
|
||
if (personalAccessKey) { | ||
const response = await getAccessToken( | ||
personalAccessKey, | ||
env, | ||
derivedAccountId | ||
); | ||
|
||
scopeGroups = response.scopeGroups.map(s => [s]); | ||
} | ||
|
||
if (name) { | ||
logger.log(i18n(`${i18nKey}.name`, { name })); | ||
} | ||
logger.log(i18n(`${i18nKey}.accountId`, { accountId: derivedAccountId })); | ||
logger.log(i18n(`${i18nKey}.scopeGroups`)); | ||
logger.log(getTableContents(scopeGroups, { border: { bodyLeft: ' ' } })); | ||
} else { | ||
logger.log(i18n(`${i18nKey}.errors.notUsingPersonalAccessKey`)); | ||
} | ||
} | ||
} | ||
|
||
export default AccountInfo; | ||
module.exports = AccountInfo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
import { Options } from 'yargs'; | ||
|
||
export type CommonArgs = { | ||
derivedAccountId: number; | ||
providedAccountId?: number; | ||
d: boolean; | ||
debug: boolean; | ||
}; | ||
|
||
export type ConfigOptions = { | ||
c?: string; | ||
config?: string; | ||
}; | ||
|
||
export type StringOptionType = Options & { | ||
type: 'string'; | ||
}; |