Show help info in REPL
#5693
-
Here is my parser and repl code: // special repl command
if let Some(input) = input.strip_prefix("\\") {
let cmd = ReplCommand::try_parse_from(input.split_whitespace())
.change_context_lazy(|| Error::Internal("failed to parse command".to_string()))?;
match cmd.cmd {
ReplSubCommand::Connect(connect) => { ... }
}
continue;
} #[derive(Debug, Parser)]
#[command(multicall = true)]
pub struct ReplCommand {
#[command(subcommand)]
pub cmd: ReplSubCommand,
}
#[derive(Debug, Subcommand)]
pub enum ReplSubCommand {
/// Connect to another server.
#[command(name = "connect")]
Connect(CommandConnect),
}
#[derive(Debug, Parser)]
pub struct CommandConnect {
/// The endpoint of the server to connect to.
#[arg(value_name = "ENDPOINT")]
pub endpoint: String,
} When running:
How can I properly handle help command and print the help info in REPL? |
Beta Was this translation helpful? Give feedback.
Answered by
epage
Aug 22, 2024
Replies: 1 comment 1 reply
-
You can see our REPL example at https://docs.rs/clap/latest/clap/_derive/_cookbook/repl_derive/index.html In that case, the difference between an error and help printing doesn't matter because we do the same thing. If you are needing to distinguish, check |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
tisonkun
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can see our REPL example at https://docs.rs/clap/latest/clap/_derive/_cookbook/repl_derive/index.html
In that case, the difference between an error and help printing doesn't matter because we do the same thing. If you are needing to distinguish, check
err.use_stderr()
.