Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add '--status' flag to analytics command #1386

Merged
merged 11 commits into from
May 2, 2024
18 changes: 14 additions & 4 deletions src/commands/config/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default class Analytics extends Command {
help: Flags.help({ char: 'h' }),
disable: Flags.boolean({ char: 'd', description: 'disable analytics', default: false }),
enable: Flags.boolean({ char: 'e', description: 'enable analytics', default: false }),
status: Flags.boolean({ char: 's', description: 'show current status of analytics' }),

};

async run() {
Expand All @@ -23,15 +25,23 @@ export default class Analytics extends Command {

if (flags.disable) {
analyticsConfigFileContent.analyticsEnabled = 'false';
this.log('Analytics disabled.');
this.log('\nAnalytics disabled.\n');
} else if (flags.enable) {
analyticsConfigFileContent.analyticsEnabled = 'true';
this.log('Analytics enabled.');
} else {
this.log('\nPlease append the "--disable" flag to the command in case you prefer to disable analytics, or use the "--enable" flag if you want to enable analytics back again.\n');
this.log('\nAnalytics enabled.\n');
} else if (!flags.status) {
this.log('\nPlease append the "--disable" flag to the command in case you prefer to disable analytics, or use the "--enable" flag if you want to enable analytics back again. In case you do not know the analytics current status, then you can append the "--status" flag to be aware of it.\n');
return;
}
await writeFile(analyticsConfigFile, JSON.stringify(analyticsConfigFileContent), { encoding: 'utf8' });

if (flags.status) {
if (analyticsConfigFileContent.analyticsEnabled === 'true') {
this.log('\nAnalytics are enabled.\n');
} else {
this.log('\nAnalytics are disabled. Please append the "--enable" flag to the command in case you prefer to enable analytics.\n');
}
}
} catch (e: any) {
switch (e.code) {
case 'ENOENT':
Expand Down
18 changes: 15 additions & 3 deletions test/integration/config/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('config:analytics', () => {
.stdout()
.command(['config:analytics', '--disable'])
.it('should show a successful message once the analytics are disabled', async (ctx, done) => {
expect(ctx.stdout).to.equal('Analytics disabled.\n');
expect(ctx.stdout).to.equal('\nAnalytics disabled.\n\n');
expect(ctx.stderr).to.equal('');
done();
});
Expand All @@ -19,7 +19,7 @@ describe('config:analytics', () => {
.stdout()
.command(['config:analytics', '--enable'])
.it('should show a successful message once the analytics are enabled', (ctx, done) => {
expect(ctx.stdout).to.equal('Analytics enabled.\n');
expect(ctx.stdout).to.equal('\nAnalytics enabled.\n\n');
expect(ctx.stderr).to.equal('');
done();
});
Expand All @@ -31,7 +31,19 @@ describe('config:analytics', () => {
.stdout()
.command(['config:analytics'])
.it('should show informational message when no flags are used', (ctx, done) => {
expect(ctx.stdout).to.equal('\nPlease append the "--disable" flag to the command in case you prefer to disable analytics, or use the "--enable" flag if you want to enable analytics back again.\n\n');
expect(ctx.stdout).to.equal('\nPlease append the "--disable" flag to the command in case you prefer to disable analytics, or use the "--enable" flag if you want to enable analytics back again. In case you do not know the analytics current status, then you can append the "--status" flag to be aware of it.\n\n');
expect(ctx.stderr).to.equal('');
done();
});
});

describe('with status flag', () => {
test
.stderr()
.stdout()
.command(['config:analytics', '--status'])
.it('should show a different informational message depending on the analytics status', (ctx, done) => {
expect(ctx.stdout).to.contain('\nAnalytics are ');
expect(ctx.stderr).to.equal('');
done();
});
Expand Down
Loading