Skip to content

Commit

Permalink
fix: escape command-line args in log
Browse files Browse the repository at this point in the history
  • Loading branch information
suo committed May 9, 2022
1 parent e88a709 commit 1018103
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ impl Linter {
"Running linter {}: {} {}",
self.code,
program[0],
arguments.join(" ")
arguments
.iter()
.map(|x| format!("'{x}'"))
.collect::<Vec<_>>()
.join(" ")
);

let start = std::time::Instant::now();
Expand Down
41 changes: 41 additions & 0 deletions src/rage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::persistent_data::PersistentDataStore;
use anyhow::Result;
use console::style;
use dialoguer::{theme::ColorfulTheme, Select};

pub fn do_rage(
persistent_data_store: &PersistentDataStore,
invocation: Option<usize>,
) -> Result<i32> {
let run = match invocation {
Some(invocation) => Some(persistent_data_store.run(invocation)?),
None => {
let runs = persistent_data_store.runs()?;
let items: Vec<String> = persistent_data_store
.runs()?
.iter()
.map(|run| run.timestamp.to_string() + ": " + &run.args.join(" "))
.collect();

let selection = Select::with_theme(&ColorfulTheme::default())
.with_prompt("Select a past invocation to report")
.items(&items)
.default(0)
.interact_opt()?;

selection.map(|i| runs.into_iter().nth(i).unwrap())
}
};

match run {
Some(run) => {
let report = persistent_data_store.get_run_report(&run)?;
print!("{}", report);
Ok(0)
}
None => {
println!("{}", style("Nothing selected, exiting.").yellow());
Ok(1)
}
}
}

0 comments on commit 1018103

Please sign in to comment.