commander#CommanderError TypeScript Examples
The following examples show how to use
commander#CommanderError.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: assert-args.ts From rediagram with MIT License | 6 votes |
export function assertArgs(name: string, pm: string): void {
if (name !== path.basename(name)) {
throw new CommanderError(1, assertArgs.key, 'name must be a directory name that can be created.');
}
const { validForNewPackages, warnings, errors } = validate(name);
if (!validForNewPackages) {
throw new CommanderError(
1,
assertArgs.key,
`name must be a package name that can be created.\n${[
...(errors ?? []).map((msg) => ` error: ${msg}`),
...(warnings ?? []).map((msg) => ` worning: ${msg}`),
].join('\n')}`,
);
}
if (fs.pathExistsSync(path.resolve(process.cwd(), name))) {
throw new CommanderError(1, assertArgs.key, `'${name}' directory already exists.`);
}
if (!['npm', 'yarn'].includes(pm)) {
throw new CommanderError(1, assertArgs.key, `'${pm}' is not supportted. choose from yarn or npm`);
}
}
Example #2
Source File: cli.ts From ardrive-cli with GNU Affero General Public License v3.0 | 5 votes |
abstract exitOverride(callback?: (commanderError: CommanderError) => void): CliApiObject;
Example #3
Source File: cli.ts From devmoji with Apache License 2.0 | 5 votes |
test("--help", async () => {
const mockCli = new MockCli()
await expect(
mockCli.testAsync(() => Cli.create(["", "", "-h"], true))
).rejects.toThrow(CommanderError)
expect(mockCli.stdout?.data).toMatch(/Usage:/)
})