-
I'm creating a new CLI which I'd like to have display the top level help content when the cli is run with no commands or flags. Right now I'm just The same applies for sub-commands that the user runs with no commands or flags. As I understand it I'd need to implement an Here is an example of what I'm trying to achieve: import { Command } from "https://deno.land/x/cliffy@v0.18.2/command/mod.ts";
import { HelpCommand } from "https://deno.land/x/cliffy@v0.18.2/command/help/mod.ts";
// Question : how to get both of these commands to print the help?
// deno run helpme.ts
// deno run helpme.ts --help
//
// And these also:
// deno run helpme.ts subcommand
// deno run helpme.ts subcommand --help
const subcommand = new Command()
.description("HelpMe Demo Sub-Command")
.action(() => {
console.log(`How can I display the same output as 'deno run helpme.ts subcommand --help' here?`)
Deno.exit(0);
});
const cmd = new Command()
.name("helpme")
.version("0.0.0")
.description("HelpMe Demo")
.action(() => {
console.log(`How can I display the same output as 'deno run helpme.ts --help' here?`)
Deno.exit(0);
})
.command("subcommand", subcommand)
.command("help", new HelpCommand().global());
try {
cmd.parse(Deno.args);
} catch (error) {
console.error("Error: ", error.message);
Deno.exit(1);
} Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi @grempe, you can use |
Beta Was this translation helpful? Give feedback.
-
I had the same issue and this discussion solved my issue! Very helpful! |
Beta Was this translation helpful? Give feedback.
Hi @grempe,
you can use
cmd.showHelp()
. It prints the help text to stdout and there is also a.getHelp()
method which returns the help text as string.