Skip to content

Commit

Permalink
feat: Add gist/pastry upload to lintrunner rage (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
oulgen authored Apr 9, 2024
1 parent 77c3ff2 commit bd224ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ enum SubCommand {
/// Choose a specific invocation to report on. 0 is the most recent run.
#[clap(long, short)]
invocation: Option<usize>,
/// Set to upload the report to github gist (if available)
#[clap(long, short, action)]
gist: bool,
/// Set to upload the report to pastry (if available)
#[clap(long, short, action)]
pastry: bool,
},
}

Expand Down Expand Up @@ -315,7 +321,11 @@ fn do_main() -> Result<i32> {
only_lint_under_config_dir,
)
}
SubCommand::Rage { invocation } => do_rage(&persistent_data_store, invocation),
SubCommand::Rage {
invocation,
gist,
pastry,
} => do_rage(&persistent_data_store, invocation, gist, pastry),
SubCommand::List => {
println!("Available linters:");
for linter in &lint_runner_config.linters {
Expand Down
27 changes: 26 additions & 1 deletion src/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use crate::persistent_data::{PersistentDataStore, RunInfo};
use anyhow::{Context, Result};
use console::style;
use dialoguer::{theme::ColorfulTheme, Select};
use std::io::Write;
use std::process::Command;
use std::process::Stdio;

fn select_past_runs(persistent_data_store: &PersistentDataStore) -> Result<Option<RunInfo>> {
let runs = persistent_data_store.past_runs()?;
Expand Down Expand Up @@ -34,9 +37,22 @@ fn select_past_runs(persistent_data_store: &PersistentDataStore) -> Result<Optio
Ok(selection.map(|i| runs.into_iter().nth(i).unwrap().0))
}

fn upload(report: String, cmd: &mut Command) -> Result<()> {
let mut child = cmd.stdin(Stdio::piped()).spawn()?;

if let Some(mut stdin) = child.stdin.take() {
stdin.write_all(report.as_bytes())?;
}

child.wait()?;
Ok(())
}

pub fn do_rage(
persistent_data_store: &PersistentDataStore,
invocation: Option<usize>,
gist: bool,
pastry: bool,
) -> Result<i32> {
let run = match invocation {
Some(invocation) => Some(persistent_data_store.past_run(invocation)?),
Expand All @@ -48,7 +64,16 @@ pub fn do_rage(
let report = persistent_data_store
.get_run_report(&run)
.context("getting selected run report")?;
print!("{}", report);
if gist {
upload(
report.clone(),
Command::new("gh").args(["gist", "create", "-"]),
)?;
} else if pastry {
upload(report.clone(), &mut Command::new("pastry"))?;
} else {
print!("{}", report);
}
}
None => {
println!("{}", style("Nothing selected, exiting.").yellow());
Expand Down

0 comments on commit bd224ae

Please sign in to comment.