Create an unformatted error
\nThis is for you need to pass the error up to\na place that has access to the Command
at which point you can call Error::format
.
Prefer Command::error
for generating errors.
Format the existing message with the Command’s context
\nCreate an error with a pre-defined message
\nSee also
\n\n\nlet cmd = clap::Command::new(\"prog\");\n\nlet mut err = clap::Error::new(ErrorKind::ValueValidation)\n .with_cmd(&cmd);\nerr.insert(ContextKind::InvalidArg, ContextValue::String(\"--foo\".to_owned()));\nerr.insert(ContextKind::InvalidValue, ContextValue::String(\"bar\".to_owned()));\n\nerr.print();
Apply Command
’s formatting to the error
Generally, this is used with Error::new
Apply an alternative formatter to the error
\nlet cmd = Command::new(\"foo\")\n .arg(Arg::new(\"input\").required(true));\nlet matches = cmd\n .try_get_matches_from([\"foo\", \"input.txt\"])\n .map_err(|e| e.apply::<KindFormatter>())\n .unwrap_or_else(|e| e.exit());
Additional information to further qualify the error
\nLookup a piece of context
\nInsert a piece of context
\nShould the message be written to stdout
or not?
Returns the exit code that .exit
will exit the process with.
When the error’s kind would print to stderr
this returns 2
,\nelse it returns 0
.
Prints the error and exits.
\nDepending on the error kind, this either prints to stderr
and exits with a status of 2
\nor prints to stdout
and exits with a status of 0
.
Prints formatted and colored error to stdout
or stderr
according to its error kind
use clap::Command;\n\nmatch Command::new(\"Command\").try_get_matches() {\n Ok(matches) => {\n // do_something\n },\n Err(err) => {\n err.print().expect(\"Error writing Error\");\n // do_something\n },\n};