From 34f0327bfc1c71475e8fcacbd1d50451c117b525 Mon Sep 17 00:00:00 2001 From: Branden Rodgers Date: Mon, 6 Jan 2025 16:36:16 -0500 Subject: [PATCH] Chore: Fix the no config error for hs --version (#1314) --- acceptance-tests/tests/commands/hs.spec.ts | 36 ++++++++++++++++++++++ bin/cli.js | 18 +++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 acceptance-tests/tests/commands/hs.spec.ts diff --git a/acceptance-tests/tests/commands/hs.spec.ts b/acceptance-tests/tests/commands/hs.spec.ts new file mode 100644 index 000000000..73494eb38 --- /dev/null +++ b/acceptance-tests/tests/commands/hs.spec.ts @@ -0,0 +1,36 @@ +import { describe, beforeAll, it, expect, afterAll } from 'vitest'; +import { TestState } from '../../lib/TestState'; + +describe('hs', () => { + let testState: TestState; + + beforeAll(async () => { + testState = new TestState(); + }); + + afterAll(() => { + testState.cleanup(); + }); + + describe('hs', () => { + it('should log out the help message', async () => { + const output = await testState.cli.executeWithTestConfig([]); + + expect(output).toContain( + 'The command line interface to interact with HubSpot' + ); + }); + + it('should log out the help message when --help is passed', async () => { + const output = await testState.cli.executeWithTestConfig(['--help']); + + expect(output).toContain( + 'The command line interface to interact with HubSpot' + ); + }); + + it('should not throw when --version is passed', async () => { + await testState.cli.executeWithTestConfig(['--version']); + }); + }); +}); diff --git a/bin/cli.js b/bin/cli.js index 85a013e38..1644f7ed0 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -108,7 +108,7 @@ const handleFailure = (msg, err, yargs) => { } if (msg === null) { - yargs.showHelp(); + yargs.showHelp('log'); process.exit(EXIT_CODES.SUCCESS); } else { process.exit(EXIT_CODES.ERROR); @@ -177,6 +177,11 @@ const SKIP_CONFIG_VALIDATION = { }; const loadConfigMiddleware = async options => { + // Skip this when no command is provided + if (!options._.length) { + return; + } + const maybeValidateConfig = () => { if ( !isTargetedCommand(options, SKIP_CONFIG_VALIDATION) && @@ -201,7 +206,11 @@ const loadConfigMiddleware = async options => { maybeValidateConfig(); }; -const checkAndWarnGitInclusionMiddleware = () => { +const checkAndWarnGitInclusionMiddleware = options => { + // Skip this when no command is provided + if (!options._.length) { + return; + } checkAndWarnGitInclusion(getConfigPath()); }; @@ -231,6 +240,11 @@ const SKIP_ACCOUNT_VALIDATION = { }; const validateAccountOptions = async options => { + // Skip this when no command is provided + if (!options._.length) { + return; + } + let validAccount = true; if (!isTargetedCommand(options, SKIP_ACCOUNT_VALIDATION)) { validAccount = await validateAccount(options);