Skip to content

Commit f6d07ec

Browse files
committed
feat: Restructure accounts commands to meet the new design guidelines
1 parent eefb1e0 commit f6d07ec

File tree

8 files changed

+16
-49
lines changed

8 files changed

+16
-49
lines changed

commands/__tests__/accounts.test.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import use from '../accounts/use';
66
import info from '../accounts/info';
77
import remove from '../accounts/remove';
88
import clean from '../accounts/clean';
9-
import { addAccountOptions, addConfigOptions } from '../../lib/commonOpts';
109

1110
jest.mock('yargs');
1211
jest.mock('../accounts/list');
@@ -15,7 +14,6 @@ jest.mock('../accounts/use');
1514
jest.mock('../accounts/info');
1615
jest.mock('../accounts/remove');
1716
jest.mock('../accounts/clean');
18-
jest.mock('../../lib/commonOpts');
1917
yargs.command.mockReturnValue(yargs);
2018
yargs.demandCommand.mockReturnValue(yargs);
2119

@@ -25,7 +23,7 @@ import accountsCommand from '../accounts';
2523
describe('commands/accounts', () => {
2624
describe('command', () => {
2725
it('should have the correct command structure', () => {
28-
expect(accountsCommand.command).toEqual('accounts');
26+
expect(accountsCommand.command).toEqual(['account', 'accounts']);
2927
});
3028
});
3129

@@ -37,7 +35,7 @@ describe('commands/accounts', () => {
3735

3836
describe('builder', () => {
3937
const subcommands = [
40-
['list', { ...list, aliases: 'ls' }],
38+
['list', list],
4139
['rename', rename],
4240
['use', use],
4341
['info', info],
@@ -52,16 +50,6 @@ describe('commands/accounts', () => {
5250
expect(yargs.demandCommand).toHaveBeenCalledWith(1, '');
5351
});
5452

55-
it('should support the correct options', () => {
56-
accountsCommand.builder(yargs);
57-
58-
expect(addConfigOptions).toHaveBeenCalledTimes(1);
59-
expect(addConfigOptions).toHaveBeenCalledWith(yargs);
60-
61-
expect(addAccountOptions).toHaveBeenCalledTimes(1);
62-
expect(addAccountOptions).toHaveBeenCalledWith(yargs);
63-
});
64-
6553
it('should add the correct number of sub commands', () => {
6654
accountsCommand.builder(yargs);
6755
expect(yargs.command).toHaveBeenCalledTimes(subcommands.length);

commands/accounts.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// @ts-nocheck
2-
const { addConfigOptions, addAccountOptions } = require('../lib/commonOpts');
32
const { i18n } = require('../lib/lang');
43
const list = require('./accounts/list');
54
const rename = require('./accounts/rename');
@@ -10,18 +9,12 @@ const clean = require('./accounts/clean');
109

1110
const i18nKey = 'commands.accounts';
1211

13-
exports.command = 'accounts';
12+
exports.command = ['account', 'accounts'];
1413
exports.describe = i18n(`${i18nKey}.describe`);
1514

1615
exports.builder = yargs => {
17-
addConfigOptions(yargs);
18-
addAccountOptions(yargs);
19-
2016
yargs
21-
.command({
22-
...list,
23-
aliases: 'ls',
24-
})
17+
.command(list)
2518
.command(rename)
2619
.command(use)
2720
.command(info)

commands/accounts/clean.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ const { trackCommandUsage } = require('../../lib/usageTracking');
88
const { i18n } = require('../../lib/lang');
99
const { loadAndValidateOptions } = require('../../lib/validation');
1010
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
11-
const {
12-
addConfigOptions,
13-
addAccountOptions,
14-
addUseEnvironmentOptions,
15-
addTestingOptions,
16-
} = require('../../lib/commonOpts');
11+
const { addTestingOptions } = require('../../lib/commonOpts');
1712
const { promptUser } = require('../../lib/prompts/promptUtils');
1813
const { getTableContents } = require('../../lib/ui/table');
1914
const SpinniesManager = require('../../lib/ui/SpinniesManager');
@@ -136,9 +131,6 @@ exports.handler = async options => {
136131
};
137132

138133
exports.builder = yargs => {
139-
addConfigOptions(yargs);
140-
addAccountOptions(yargs);
141-
addUseEnvironmentOptions(yargs);
142134
addTestingOptions(yargs);
143135

144136
yargs.example([['$0 accounts clean']]);

commands/accounts/info.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
const { logger } = require('@hubspot/local-dev-lib/logger');
33
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
44
const { getAccessToken } = require('@hubspot/local-dev-lib/personalAccessKey');
5-
const { addAccountOptions, addConfigOptions } = require('../../lib/commonOpts');
5+
const { addConfigOptions } = require('../../lib/commonOpts');
66
const { loadAndValidateOptions } = require('../../lib/validation');
77
const { i18n } = require('../../lib/lang');
88
const { getTableContents } = require('../../lib/ui/table');
99

1010
const i18nKey = 'commands.accounts.subcommands.info';
1111
exports.describe = i18n(`${i18nKey}.describe`);
1212

13-
exports.command = 'info [--account]';
13+
exports.command = 'info [account]';
1414

1515
exports.handler = async options => {
1616
await loadAndValidateOptions(options);
@@ -40,7 +40,6 @@ exports.handler = async options => {
4040

4141
exports.builder = yargs => {
4242
addConfigOptions(yargs);
43-
addAccountOptions(yargs);
4443

4544
yargs.example([
4645
['$0 accounts info', i18n(`${i18nKey}.examples.default`)],

commands/accounts/list.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const {
1111
} = require('@hubspot/local-dev-lib/config/getAccountIdentifier');
1212
const { getTableContents, getTableHeader } = require('../../lib/ui/table');
1313

14-
const { addConfigOptions, addAccountOptions } = require('../../lib/commonOpts');
1514
const { trackCommandUsage } = require('../../lib/usageTracking');
1615
const { loadAndValidateOptions } = require('../../lib/validation');
1716
const { isSandbox, isDeveloperTestAccount } = require('../../lib/accountTypes');
@@ -24,7 +23,7 @@ const {
2423

2524
const i18nKey = 'commands.accounts.subcommands.list';
2625

27-
exports.command = 'list';
26+
exports.command = ['list', 'ls'];
2827
exports.describe = i18n(`${i18nKey}.describe`);
2928

3029
const sortAndMapPortals = portals => {
@@ -112,10 +111,6 @@ exports.handler = async options => {
112111
};
113112

114113
exports.builder = yargs => {
115-
addConfigOptions(yargs);
116-
addAccountOptions(yargs);
117-
118114
yargs.example([['$0 accounts list']]);
119-
120115
return yargs;
121116
};

commands/accounts/remove.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ const { loadAndValidateOptions } = require('../../lib/validation');
1616

1717
const i18nKey = 'commands.accounts.subcommands.remove';
1818

19-
exports.command = 'remove [--account]';
19+
exports.command = 'remove <account>';
2020
exports.describe = i18n(`${i18nKey}.describe`);
2121

2222
exports.handler = async options => {
2323
await loadAndValidateOptions(options, false);
24+
const { account } = options;
25+
let accountToRemove = account;
2426

2527
let config = getConfig();
2628

27-
let accountToRemove = options.providedAccountId;
28-
2929
if (accountToRemove && !getAccountIdFromConfig(accountToRemove)) {
3030
logger.error(
3131
i18n(`${i18nKey}.errors.accountNotFound`, {
@@ -69,7 +69,7 @@ exports.handler = async options => {
6969
};
7070

7171
exports.builder = yargs => {
72-
yargs.option('account', {
72+
yargs.positional('account', {
7373
describe: i18n(`${i18nKey}.options.account.describe`),
7474
type: 'string',
7575
});

commands/accounts/use.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ exports.handler = async options => {
5252
};
5353

5454
exports.builder = yargs => {
55-
yargs.option('account', {
55+
yargs.positional('account', {
5656
describe: i18n(`${i18nKey}.options.account.describe`),
5757
type: 'string',
5858
});

lang/en.lyaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ en:
1010
loadConfigMiddleware:
1111
configFileExists: "A configuration file already exists at {{ configPath }}. To specify a new configuration file, delete the existing one and try again."
1212
accounts:
13-
describe: "Commands for working with accounts."
13+
describe: "Commands for managing configured accounts."
1414
subcommands:
1515
list:
1616
accounts: "{{#bold}}Accounts{{/bold}}:"
@@ -22,7 +22,7 @@ en:
2222
authType: "Auth Type"
2323
name: "Name"
2424
rename:
25-
describe: "Rename account in config."
25+
describe: "Rename an account in the config."
2626
positionals:
2727
accountName:
2828
describe: "Name of account to be renamed."
@@ -63,7 +63,7 @@ en:
6363
accountRemoved: "Account \"{{ accountName }}\" removed from the config"
6464
info:
6565
accountId: "{{#bold}}Account ID{{/bold}}: {{ accountId }}"
66-
describe: "Print information about the default account, or about the account specified with the \"--account\" option."
66+
describe: "Print information about the default account, or about the account specified with the \"account\" option."
6767
errors:
6868
notUsingPersonalAccessKey: "This command currently only supports fetching scopes for the personal access key auth type."
6969
examples:

0 commit comments

Comments
 (0)