Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scmd): Fix messages printed as error wrongly #3438

Merged
merged 1 commit into from
May 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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