fix: handle more failure cases

This commit is contained in:
cha0s 2024-02-10 12:52:34 -06:00
parent 1eff7f4a65
commit 61f258e414
2 changed files with 35 additions and 2 deletions

View File

@ -34,7 +34,7 @@ const program = new Command();
program
.enablePositionalOptions()
.name('flecks')
.usage('[command] [...]');
.usage('<command> [...]');
// Bootstrap.
(async () => {
debugSilly('bootstrapping flecks...');
@ -43,6 +43,9 @@ program
// Register commands.
const commands = await flecks.invokeMergeUniqueAsync('@flecks/build.commands', program);
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) {
const {
action,
@ -63,5 +66,5 @@ program
cmd.action(forwardProcessCode(action));
}
// Parse commandline.
program.parse(process.argv);
await program.parseAsync(process.argv);
})();

View 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');
});