Skip to content

Commit

Permalink
chore: Add flag to not track the hs init command (#1244)
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-yeager authored Nov 15, 2024
1 parent a32a4a8 commit 4be0bb4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion acceptance-tests/lib/TestState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class TestState {
async initializeAuth() {
try {
await this.cli.executeWithTestConfig(
['init'],
['init', '--disable-tracking'],
getInitPromptSequence(this.getPAK())
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Account Management Flow', () => {
describe('hs init', () => {
it('should generate a config file', async () => {
await testState.cli.executeWithTestConfig(
['init'],
['init', '--disable-tracking'],
getInitPromptSequence(testState.getPAK(), accountName)
);

Expand Down
5 changes: 5 additions & 0 deletions commands/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ describe('commands/init', () => {
default: 'personalaccesskey',
}),
account: expect.objectContaining({ type: 'string' }),
'disable-tracking': expect.objectContaining({
type: 'boolean',
hidden: true,
default: false,
}),
});

expect(addConfigOptions).toHaveBeenCalledTimes(1);
Expand Down
40 changes: 29 additions & 11 deletions commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,17 @@ exports.handler = async options => {
auth: authType = PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
c,
account: optionalAccount,
disableTracking,
} = options;
const configPath = (c && path.join(getCwd(), c)) || getConfigPath();
setLogLevel(options);
trackCommandUsage('init', {
authType,
});

if (!disableTracking) {
trackCommandUsage('init', {
authType,
});
}

const env = options.qa ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD;

if (fs.existsSync(configPath)) {
Expand All @@ -122,8 +127,12 @@ exports.handler = async options => {
process.exit(EXIT_CODES.ERROR);
}

trackAuthAction('init', authType, TRACKING_STATUS.STARTED);
if (!disableTracking) {
await trackAuthAction('init', authType, TRACKING_STATUS.STARTED);
}

createEmptyConfigFile({ path: configPath });

handleExit(deleteEmptyConfigFile);

try {
Expand Down Expand Up @@ -153,16 +162,20 @@ exports.handler = async options => {
);
uiFeatureHighlight(['helpCommand', 'authCommand', 'accountsListCommand']);

await trackAuthAction(
'init',
authType,
TRACKING_STATUS.COMPLETE,
accountId
);
if (!disableTracking) {
await trackAuthAction(
'init',
authType,
TRACKING_STATUS.COMPLETE,
accountId
);
}
process.exit(EXIT_CODES.SUCCESS);
} catch (err) {
logError(err);
await trackAuthAction('init', authType, TRACKING_STATUS.ERROR);
if (!disableTracking) {
await trackAuthAction('init', authType, TRACKING_STATUS.ERROR);
}
process.exit(EXIT_CODES.ERROR);
}
};
Expand All @@ -185,6 +198,11 @@ exports.builder = yargs => {
describe: i18n(`${i18nKey}.options.account.describe`),
type: 'string',
},
'disable-tracking': {
type: 'boolean',
hidden: true,
default: false,
},
});

addConfigOptions(yargs);
Expand Down

0 comments on commit 4be0bb4

Please sign in to comment.