Closed melMass closed 4 years ago
Subcommand is already supported via @:command public var info:InfoCommand = new InfoCommand();
@kevinresol Thanks !!
Glad to learn that! The only issue I have now is that it does not take the doc comment?
I tried above the meta, above the var declaration and above the class, none worked.
Is there a more advanced doc somewhere?
It doesn't work as expected using your method.
I use to be able to do:
mycli new project
mycli
being the main commandnew
declared using your method:
@:command("new") public var new_command:NewCommand = new NewCommand()
project
a command method of NewCommand. I'm I missing something ?
Just tested and it is working for me (https://github.com/haxetink/tink_cli/commit/25aaa82c763c5840ad54cec623330d1deaed28f1)
Can you give me more details?
Sorry for the delay, I will put together a sample of my issue later today!
The issue I had was that for the project
command I rely on the Prompt
argument, so there is no Rest
and Sys.args is not filtered!
So it is working as expected.
Is there a way though to handle both Prompt
and Rest
.
Please post an example
@:command("project")
public function project_command(?prompt:Prompt,?rest:Rest<String>) {
trace(rest);
return prompt.prompt(Simple('Project Name').next( (input) -> {
trace('Creating project ${input}');
return Noise;
});
}
and what is the error you are getting?
I used a workaround on the project that needed it, as it's unrelated to the original answer I'll close that one and reopen another one if I face the issue again. Thanks for the support
Hi Kevin,
I'm not sure that you are interested in this, or even if it's the right approach, but as I did not think
tink_cli
was able to do that, here is a small writeup on Subcommands withtink_cli
:See Kevin's answer for the official right approach. 🥇
I just ended a project where I needed to build a CLI with subcommands. Haxe is by far my favorite coding language nowadays I wanted to give tink_cli another try (first discovered the lib a year ago). One of the requirements I had was subcommands with their own flags. Here is how I went about it: ## A `MainCommand` to wire them all The idea is pretty simple, your main command is just used to run your subcommands as commands... An example will be clearer. Let's take this basic example: #### Main.hx ```haxe class Main { static function main() { Cli.process(Sys.args(), new MainCommand()).handle(Main.exit); } } ``` #### MainCommand.hx ```haxe class MainCommand { /** Be more verbose */ public var verbose:Bool=false; public function new() {} @:defaultCommand public function main_command(rest:Rest