Skip to content

Commit

Permalink
cli Add long option --oneline to -1
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
DaveMcEwan committed Jun 27, 2023
1 parent f9ddcf4 commit 0386847
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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();
Expand All @@ -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)?;
}
}
}
Expand All @@ -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;
}
}
Expand All @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Printer {
}

#[cfg_attr(tarpaulin, skip)]
fn print_single(
fn print_oneline(
&mut self,
src: &str,
print_pos: usize,
Expand Down Expand Up @@ -332,16 +332,16 @@ 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)
.with_context(|| format!("failed to open: '{}'", failed.path.to_string_lossy()))?;
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,
Expand Down Expand Up @@ -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);
}
Expand All @@ -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,
Expand Down

0 comments on commit 0386847

Please sign in to comment.