@@ -2,6 +2,9 @@ use crate::persistent_data::{PersistentDataStore, RunInfo};
22use anyhow:: { Context , Result } ;
33use console:: style;
44use dialoguer:: { theme:: ColorfulTheme , Select } ;
5+ use std:: io:: Write ;
6+ use std:: process:: Command ;
7+ use std:: process:: Stdio ;
58
69fn 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+
3751pub 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