Skip to content

Commit

Permalink
fix(scmd): Fix messages printed as error wrongly (#3438)
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored May 31, 2022
1 parent a43584b commit aa4d426
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions commons/scmd/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
print_action_result, CommandAction, CommandExec, CustomCommand, HistoryOp, OutputFormat,
};
use anyhow::Result;
use clap::Parser;
use clap::{Arg, Command};
use clap::{ErrorKind, Parser};
use once_cell::sync::Lazy;
use serde_json::Value;
use std::collections::HashMap;
Expand Down Expand Up @@ -199,9 +199,18 @@ where
T: Into<OsString> + Clone,
{
let mut app = self.app;
let matches = app
.try_get_matches_from_mut(iter)
.map_err(CmdError::ClapError)?;
let matches = match app.try_get_matches_from_mut(iter) {
Ok(matches) => matches,
Err(err) => {
return match err.kind() {
ErrorKind::DisplayVersion | ErrorKind::DisplayHelp => {
Ok((OutputFormat::TABLE, Ok(Value::String(err.to_string()))))
}
_ => Err(CmdError::ClapError(err).into()),
};
}
};

let output_format = matches
.value_of(G_OUTPUT_FORMAT_ARG)
.expect("output-format arg must exist")
Expand Down

0 comments on commit aa4d426

Please sign in to comment.