fix: handle more failure cases
This commit is contained in:
parent
1eff7f4a65
commit
61f258e414
|
@ -34,7 +34,7 @@ const program = new Command();
|
||||||
program
|
program
|
||||||
.enablePositionalOptions()
|
.enablePositionalOptions()
|
||||||
.name('flecks')
|
.name('flecks')
|
||||||
.usage('[command] [...]');
|
.usage('<command> [...]');
|
||||||
// Bootstrap.
|
// Bootstrap.
|
||||||
(async () => {
|
(async () => {
|
||||||
debugSilly('bootstrapping flecks...');
|
debugSilly('bootstrapping flecks...');
|
||||||
|
@ -43,6 +43,9 @@ program
|
||||||
// Register commands.
|
// Register commands.
|
||||||
const commands = await flecks.invokeMergeUniqueAsync('@flecks/build.commands', program);
|
const commands = await flecks.invokeMergeUniqueAsync('@flecks/build.commands', program);
|
||||||
const keys = Object.keys(commands).sort();
|
const keys = Object.keys(commands).sort();
|
||||||
|
if (0 === keys.length) {
|
||||||
|
program.error('No flecks commands defined! You probably forgot to install packages in this project.');
|
||||||
|
}
|
||||||
for (let i = 0; i < keys.length; ++i) {
|
for (let i = 0; i < keys.length; ++i) {
|
||||||
const {
|
const {
|
||||||
action,
|
action,
|
||||||
|
@ -63,5 +66,5 @@ program
|
||||||
cmd.action(forwardProcessCode(action));
|
cmd.action(forwardProcessCode(action));
|
||||||
}
|
}
|
||||||
// Parse commandline.
|
// Parse commandline.
|
||||||
program.parse(process.argv);
|
await program.parseAsync(process.argv);
|
||||||
})();
|
})();
|
||||||
|
|
30
packages/build/test/server/cli-no-commands.js
Normal file
30
packages/build/test/server/cli-no-commands.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import {writeFile} from 'fs/promises';
|
||||||
|
import {join} from 'path';
|
||||||
|
|
||||||
|
import {createWorkspace} from '@flecks/core/build/testing';
|
||||||
|
import {
|
||||||
|
binaryPath,
|
||||||
|
pipesink,
|
||||||
|
processCode,
|
||||||
|
spawnWith,
|
||||||
|
} from '@flecks/core/server';
|
||||||
|
import {expect} from 'chai';
|
||||||
|
|
||||||
|
it('fails predictably if no commands are defined', async () => {
|
||||||
|
const workspace = await createWorkspace();
|
||||||
|
await writeFile(join(workspace, 'package.json'), '{}');
|
||||||
|
const child = spawnWith(
|
||||||
|
[await binaryPath('flecks', '@flecks/build')],
|
||||||
|
{
|
||||||
|
stdio: 'pipe',
|
||||||
|
env: {
|
||||||
|
FLECKS_CORE_ROOT: workspace,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const buffer = await pipesink(child.stderr);
|
||||||
|
expect(await processCode(child))
|
||||||
|
.to.equal(1);
|
||||||
|
expect(buffer.toString())
|
||||||
|
.to.contain('No flecks commands defined');
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user