From 5865e96aa2150be6260b6d57384f2c89d05cf784 Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Tue, 23 Apr 2024 18:16:53 +0200 Subject: [PATCH 1/7] Add --status flag --- src/commands/config/analytics.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commands/config/analytics.ts b/src/commands/config/analytics.ts index e9c1fdaf224..4d5806235a7 100644 --- a/src/commands/config/analytics.ts +++ b/src/commands/config/analytics.ts @@ -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 analytics current status' }), + }; async run() { @@ -27,11 +29,15 @@ export default class Analytics extends Command { } else if (flags.enable) { analyticsConfigFileContent.analyticsEnabled = 'true'; this.log('Analytics enabled.'); - } else { + } 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.\n'); return; } await writeFile(analyticsConfigFile, JSON.stringify(analyticsConfigFileContent), { encoding: 'utf8' }); + + if (flags.status) { + this.log(analyticsConfigFileContent.analyticsEnabled); + } } catch (e: any) { switch (e.code) { case 'ENOENT': From b3b8d94b2d0980012203529f00c317cc2820893b Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Tue, 30 Apr 2024 19:58:35 +0200 Subject: [PATCH 2/7] Improve informational messages --- src/commands/config/analytics.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/commands/config/analytics.ts b/src/commands/config/analytics.ts index 4d5806235a7..bcd58af9536 100644 --- a/src/commands/config/analytics.ts +++ b/src/commands/config/analytics.ts @@ -25,18 +25,22 @@ 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.'); + 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.\n'); + 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) { - this.log(analyticsConfigFileContent.analyticsEnabled); + if (analyticsConfigFileContent.analyticsEnabled === 'true') { + this.log('\nAnalytics are enabled. Please append the "--disable" flag to the command in case you prefer to disable analytics.\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) { From 80af106f3ed8eac7bc91f8b4202f69c25b1a5999 Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Tue, 30 Apr 2024 20:09:46 +0200 Subject: [PATCH 3/7] Fix failing tests --- test/integration/config/analytics.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/config/analytics.test.ts b/test/integration/config/analytics.test.ts index 80471fbb78b..beca18f386a 100644 --- a/test/integration/config/analytics.test.ts +++ b/test/integration/config/analytics.test.ts @@ -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(); }); @@ -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(); }); @@ -31,7 +31,7 @@ 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(); }); From 6f0f0dc21fda84c178677b207a70e4f26de3eb2f Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Thu, 2 May 2024 10:16:40 +0200 Subject: [PATCH 4/7] Add requested change --- src/commands/config/analytics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/config/analytics.ts b/src/commands/config/analytics.ts index bcd58af9536..3ce52963063 100644 --- a/src/commands/config/analytics.ts +++ b/src/commands/config/analytics.ts @@ -12,7 +12,7 @@ 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 analytics current status' }), + status: Flags.boolean({ char: 's', description: 'show current status of analytics' }), }; From 57a7d1152ac9aed10ba31fa8a2639fa9591b3a22 Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Thu, 2 May 2024 10:34:55 +0200 Subject: [PATCH 5/7] Add more tests --- test/integration/config/analytics.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/integration/config/analytics.test.ts b/test/integration/config/analytics.test.ts index beca18f386a..4d95d641e08 100644 --- a/test/integration/config/analytics.test.ts +++ b/test/integration/config/analytics.test.ts @@ -36,4 +36,16 @@ describe('config:analytics', () => { 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(); + }); + }); }); From 21e87cf52e0086e63b6a3f2b836c57742488b12b Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Thu, 2 May 2024 10:43:22 +0200 Subject: [PATCH 6/7] Empty commit From 33afea88716e23ea4ed8eca005b3af51c3d76167 Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Thu, 2 May 2024 11:11:57 +0200 Subject: [PATCH 7/7] Update info message when analytics enabled Co-authored-by: Khuda Dad Nomani <32505158+KhudaDad414@users.noreply.github.com> --- src/commands/config/analytics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/config/analytics.ts b/src/commands/config/analytics.ts index 3ce52963063..b8cb1303fbf 100644 --- a/src/commands/config/analytics.ts +++ b/src/commands/config/analytics.ts @@ -37,7 +37,7 @@ export default class Analytics extends Command { if (flags.status) { if (analyticsConfigFileContent.analyticsEnabled === 'true') { - this.log('\nAnalytics are enabled. Please append the "--disable" flag to the command in case you prefer to disable analytics.\n'); + 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'); }