-
-
Notifications
You must be signed in to change notification settings - Fork 38
Closed
Labels
Status: AbandonedDropped and not into considerationDropped and not into consideration
Description
Package version
13.3.0
Describe the bug
Hello,
I am trying to use ace to build a cli tool outside of Adonis. Inspired by the toolkit command I wrote the following code:
import "reflect-metadata";
import { BaseCommand, args, Kernel, ListLoader, HelpCommand } from "@adonisjs/ace";
class Demo extends BaseCommand {
public static commandName = "demo";
@args.string({ description: "first arg" })
declare first_arg: string;
@args.string({ description: "second arg" })
declare second_arg: string;
public async run() {
this.logger.info(`Hello from demo command`);
}
}
const kernel = Kernel.create();
kernel.addLoader(new ListLoader([Demo]));
kernel.defineFlag("help", {
type: "boolean",
description: HelpCommand.description,
});
kernel.on("help", async (command, $kernel, parsed) => {
parsed.args.unshift(command.commandName);
const help = new HelpCommand($kernel, parsed, kernel.ui, kernel.prompt);
await help.exec();
return $kernel.shortcircuit();
});
await kernel.handle(process.argv.splice(2));My understanding is that this part makes the flag --help available for all commands:
kernel.defineFlag("help", {
type: "boolean",
description: HelpCommand.description,
});
kernel.on("help", async (command, $kernel, parsed) => {
parsed.args.unshift(command.commandName);
const help = new HelpCommand($kernel, parsed, kernel.ui, kernel.prompt);
await help.exec();
return $kernel.shortcircuit();
});However, when I run node --import tsx main.ts demo --help I get the following error:
Usage:
demo <first-arg> <second-arg>
Arguments:
first-arg first arg
second-arg second arg
ERROR Missing required argument "second_arg"
Note the error at the end of the output.
This only happens when my Demo command has more than one argument.
Am I doing something wrong here?
Reproduction repo
Metadata
Metadata
Assignees
Labels
Status: AbandonedDropped and not into considerationDropped and not into consideration