Skip to content

Commit

Permalink
Chore: Fix the no config error for hs --version (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandenrodgers authored Jan 6, 2025
1 parent 31b9051 commit 34f0327
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
36 changes: 36 additions & 0 deletions acceptance-tests/tests/commands/hs.spec.ts
Original file line number Diff line number Diff line change
@@ -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']);
});
});
});
18 changes: 16 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) &&
Expand All @@ -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());
};

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 34f0327

Please sign in to comment.