Skip to content

Commit bd224ae

Browse files
authored
feat: Add gist/pastry upload to lintrunner rage (#70)
1 parent 77c3ff2 commit bd224ae

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ enum SubCommand {
141141
/// Choose a specific invocation to report on. 0 is the most recent run.
142142
#[clap(long, short)]
143143
invocation: Option<usize>,
144+
/// Set to upload the report to github gist (if available)
145+
#[clap(long, short, action)]
146+
gist: bool,
147+
/// Set to upload the report to pastry (if available)
148+
#[clap(long, short, action)]
149+
pastry: bool,
144150
},
145151
}
146152

@@ -315,7 +321,11 @@ fn do_main() -> Result<i32> {
315321
only_lint_under_config_dir,
316322
)
317323
}
318-
SubCommand::Rage { invocation } => do_rage(&persistent_data_store, invocation),
324+
SubCommand::Rage {
325+
invocation,
326+
gist,
327+
pastry,
328+
} => do_rage(&persistent_data_store, invocation, gist, pastry),
319329
SubCommand::List => {
320330
println!("Available linters:");
321331
for linter in &lint_runner_config.linters {

src/rage.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use crate::persistent_data::{PersistentDataStore, RunInfo};
22
use anyhow::{Context, Result};
33
use console::style;
44
use dialoguer::{theme::ColorfulTheme, Select};
5+
use std::io::Write;
6+
use std::process::Command;
7+
use std::process::Stdio;
58

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

40+
fn upload(report: String, cmd: &mut Command) -> Result<()> {
41+
let mut child = cmd.stdin(Stdio::piped()).spawn()?;
42+
43+
if let Some(mut stdin) = child.stdin.take() {
44+
stdin.write_all(report.as_bytes())?;
45+
}
46+
47+
child.wait()?;
48+
Ok(())
49+
}
50+
3751
pub fn do_rage(
3852
persistent_data_store: &PersistentDataStore,
3953
invocation: Option<usize>,
54+
gist: bool,
55+
pastry: bool,
4056
) -> Result<i32> {
4157
let run = match invocation {
4258
Some(invocation) => Some(persistent_data_store.past_run(invocation)?),
@@ -48,7 +64,16 @@ pub fn do_rage(
4864
let report = persistent_data_store
4965
.get_run_report(&run)
5066
.context("getting selected run report")?;
51-
print!("{}", report);
67+
if gist {
68+
upload(
69+
report.clone(),
70+
Command::new("gh").args(["gist", "create", "-"]),
71+
)?;
72+
} else if pastry {
73+
upload(report.clone(), &mut Command::new("pastry"))?;
74+
} else {
75+
print!("{}", report);
76+
}
5277
}
5378
None => {
5479
println!("{}", style("Nothing selected, exiting.").yellow());

0 commit comments

Comments
 (0)