From 03868471709998fdd68bcee7a3d1f73fcdcf8c98 Mon Sep 17 00:00:00 2001 From: damc Date: Tue, 27 Jun 2023 15:17:01 +0200 Subject: [PATCH] cli Add long option `--oneline` to `-1` - Rename internal `single` -> `oneline` to match. Personally, I think it's more descriptive too. - `-1` can be difficult to distinguish from `-l` in some fonts. - Use the same name "oneline" as `git log` which has similar behaviour. --- src/main.rs | 20 ++++++++++---------- src/printer.rs | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1014a4ec..6ada7c9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,9 +74,9 @@ pub struct Opt { #[clap(long = "ignore-include")] pub ignore_include: bool, - /// Print results by single line - #[clap(short = '1')] - pub single: bool, + /// Print one rule failure message per line + #[clap(short = '1', long = "oneline")] + pub oneline: bool, /// Suppress messages #[clap(short = 's', long = "silent")] @@ -262,7 +262,7 @@ pub fn run_opt_config(printer: &mut Printer, opt: &Opt, config: Config) -> Resul defines = new_defines; } Err(x) => { - print_parser_error(printer, x, opt.single)?; + print_parser_error(printer, x, opt.oneline)?; pass = false; } } @@ -279,7 +279,7 @@ pub fn run_opt_config(printer: &mut Printer, opt: &Opt, config: Config) -> Resul for failed in linter.textrules_check(&line_stripped, &path, &beg) { pass = false; if !opt.silent { - printer.print_failed(&failed, opt.single, opt.github_actions)?; + printer.print_failed(&failed, opt.oneline, opt.github_actions)?; } } beg += line.len(); @@ -294,7 +294,7 @@ pub fn run_opt_config(printer: &mut Printer, opt: &Opt, config: Config) -> Resul for failed in linter.syntaxrules_check(&syntax_tree, &node) { pass = false; if !opt.silent { - printer.print_failed(&failed, opt.single, opt.github_actions)?; + printer.print_failed(&failed, opt.oneline, opt.github_actions)?; } } } @@ -306,7 +306,7 @@ pub fn run_opt_config(printer: &mut Printer, opt: &Opt, config: Config) -> Resul } } Err(x) => { - print_parser_error(printer, x, opt.single)?; + print_parser_error(printer, x, opt.oneline)?; pass = false; } } @@ -328,14 +328,14 @@ pub fn run_opt_config(printer: &mut Printer, opt: &Opt, config: Config) -> Resul fn print_parser_error( printer: &mut Printer, error: SvParserError, - single: bool, + oneline: bool, ) -> Result<(), Error> { match error { SvParserError::Parse(Some((path, pos))) => { - printer.print_parse_error(&path, pos, single)?; + printer.print_parse_error(&path, pos, oneline)?; } SvParserError::Preprocess(Some((path, pos))) => { - printer.print_preprocess_error(&path, pos, single)?; + printer.print_preprocess_error(&path, pos, oneline)?; } SvParserError::Include { source: x } => { if let SvParserError::File { path: x, .. } = *x { diff --git a/src/printer.rs b/src/printer.rs index 214be55e..a277ecee 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -206,7 +206,7 @@ impl Printer { } #[cfg_attr(tarpaulin, skip)] - fn print_single( + fn print_oneline( &mut self, src: &str, print_pos: usize, @@ -332,7 +332,7 @@ impl Printer { pub fn print_failed( &mut self, failed: &LintFailed, - single: bool, + oneline: bool, github_actions: bool, ) -> Result<(), Error> { let mut f = File::open(&failed.path) @@ -340,8 +340,8 @@ impl Printer { let mut s = String::new(); let _ = f.read_to_string(&mut s); - if single { - self.print_single(&s, failed.beg, "Fail", &failed.path, Some(&failed.hint)); + if oneline { + self.print_oneline(&s, failed.beg, "Fail", &failed.path, Some(&failed.hint)); } else { self.print_pretty( &s, @@ -375,15 +375,15 @@ impl Printer { &mut self, path: &Path, error_pos: usize, - single: bool, + oneline: bool, ) -> Result<(), Error> { let mut f = File::open(path) .with_context(|| format!("failed to open: '{}'", path.to_string_lossy()))?; let mut s = String::new(); let _ = f.read_to_string(&mut s); - if single { - self.print_single(&s, error_pos, "Error", path, Some("parse error")); + if oneline { + self.print_oneline(&s, error_pos, "Error", path, Some("parse error")); } else { self.print_pretty(&s, error_pos, 1, "Error", "parse error", path, None, None); } @@ -395,15 +395,15 @@ impl Printer { &mut self, path: &Path, error_pos: usize, - single: bool, + oneline: bool, ) -> Result<(), Error> { let mut f = File::open(path) .with_context(|| format!("failed to open: '{}'", path.to_string_lossy()))?; let mut s = String::new(); let _ = f.read_to_string(&mut s); - if single { - self.print_single(&s, error_pos, "Error", path, Some("preprocess error")); + if oneline { + self.print_oneline(&s, error_pos, "Error", path, Some("preprocess error")); } else { self.print_pretty( &s,