Skip to content

Commit 8b95e7b

Browse files
committed
fix: unify output controlling commands into --output
1 parent 14495be commit 8b95e7b

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::{bail, Context, Result};
2+
use clap::ArgEnum;
23
use console::{style, Term};
34
use indicatif::{MultiProgress, ProgressBar};
45
use linter::Linter;
@@ -129,6 +130,7 @@ pub enum RevisionOpt {
129130
MergeBaseWith(String),
130131
}
131132

133+
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ArgEnum)]
132134
pub enum RenderOpt {
133135
Default,
134136
Json,

src/main.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,11 @@ struct Args {
5555
#[clap(long)]
5656
take: Option<String>,
5757

58-
/// If set, lintrunner will render lint messages as JSON, according to the
59-
/// LintMessage spec.
60-
#[clap(long)]
61-
json: bool,
62-
63-
/// If set, lintrunner will render lint messages in a compact format, one
64-
/// line per message
65-
#[clap(long, conflicts_with = "json")]
66-
oneline: bool,
58+
/// With 'default' show lint issues in human-readable format, for interactive use.
59+
/// With 'json', show lint issues as machine-readable JSON (one per line)
60+
/// With 'oneline', show lint issues in compact format (one per line)
61+
#[clap(long, arg_enum, default_value_t = RenderOpt::Default)]
62+
output: RenderOpt,
6763

6864
#[clap(subcommand)]
6965
cmd: Option<SubCommand>,
@@ -94,7 +90,7 @@ fn do_main() -> Result<i32> {
9490
console::set_colors_enabled(true);
9591
console::set_colors_enabled_stderr(true);
9692
}
97-
let log_level = match (args.verbose, args.json) {
93+
let log_level = match (args.verbose, args.output != RenderOpt::Default) {
9894
// Default
9995
(0, false) => log::LevelFilter::Info,
10096
// If just json is asked for, suppress most output except hard errors.
@@ -126,7 +122,7 @@ fn do_main() -> Result<i32> {
126122

127123
let linters = get_linters_from_config(&config_path, skipped_linters, taken_linters)?;
128124

129-
let enable_spinners = args.verbose == 0 && !args.json;
125+
let enable_spinners = args.verbose == 0 && args.output == RenderOpt::Default;
130126

131127
let paths_to_lint = if let Some(paths_file) = args.paths_from {
132128
let path_file = AbsPath::try_from(&paths_file)
@@ -148,14 +144,6 @@ fn do_main() -> Result<i32> {
148144
RevisionOpt::Head
149145
};
150146

151-
let render_opt = if args.json {
152-
RenderOpt::Json
153-
} else if args.oneline {
154-
RenderOpt::Oneline
155-
} else {
156-
RenderOpt::Default
157-
};
158-
159147
match args.cmd {
160148
Some(SubCommand::Init { dry_run }) => {
161149
// Just run initialization commands, don't actually lint.
@@ -167,7 +155,7 @@ fn do_main() -> Result<i32> {
167155
linters,
168156
paths_to_lint,
169157
args.apply_patches,
170-
render_opt,
158+
args.output,
171159
enable_spinners,
172160
revision_opt,
173161
)

tests/integration_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn simple_linter_oneline() -> Result<()> {
162162
cmd.arg(format!("--config={}", config.path().to_str().unwrap()));
163163
// Run on a file to ensure that the linter is run.
164164
cmd.arg("README.md");
165-
cmd.arg("--oneline");
165+
cmd.arg("--output=oneline");
166166
cmd.assert().failure();
167167
assert_output_snapshot("simple_linter_oneline", &mut cmd)?;
168168

0 commit comments

Comments
 (0)