mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
Merge pull request #396 from toddbluhm/kh/invoke-error
feat(cli): provide a more helpful error if there's no command
This commit is contained in:
commit
24e8d18f05
@ -45,6 +45,13 @@ export async function EnvCmd(
|
||||
commandArgs = commandArgs.map(arg => expandEnvs(arg, env))
|
||||
}
|
||||
|
||||
if (!command) {
|
||||
throw new Error(
|
||||
'env-cmd cannot be used as a standalone command. ' +
|
||||
'Refer to the documentation for usage examples: https://npm.im/env-cmd',
|
||||
);
|
||||
}
|
||||
|
||||
// Execute the command with the given environment variables
|
||||
const proc = spawn(command, commandArgs, {
|
||||
stdio: 'inherit',
|
||||
|
||||
@ -209,4 +209,22 @@ describe('EnvCmd', (): void => {
|
||||
assert.fail('Should not get here.')
|
||||
},
|
||||
)
|
||||
|
||||
it('provides a helpful error if the CLI is incorrectly invoked', async () => {
|
||||
getEnvVarsStub.returns({ BOB: 'test' });
|
||||
try {
|
||||
await envCmdLib.EnvCmd({
|
||||
command: '',
|
||||
commandArgs: [],
|
||||
envFile: {
|
||||
filePath: './.env',
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
assert.instanceOf(e, Error);
|
||||
assert.include(e.message, 'cannot be used as a standalone');
|
||||
return;
|
||||
}
|
||||
assert.fail('Should not get here.');
|
||||
});
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user