File tree Expand file tree Collapse file tree 6 files changed +129
-10
lines changed Expand file tree Collapse file tree 6 files changed +129
-10
lines changed Original file line number Diff line number Diff line change @@ -8,3 +8,4 @@ anyhow = "1"
8
8
clap = { version = " 4" , features = [" derive" ] }
9
9
toml = " 0.8"
10
10
serde = { version = " 1" , features = [" derive" ] }
11
+ which = " 8"
Original file line number Diff line number Diff line change 1
1
use anyhow:: Context ;
2
2
use clap:: Parser ;
3
- use rustc_josh_sync :: JoshConfig ;
3
+ use josh_sync :: JoshConfig ;
4
4
5
5
const DEFAULT_CONFIG_PATH : & str = "josh-sync.toml" ;
6
6
7
7
#[ derive( clap:: Parser ) ]
8
8
struct Args {
9
9
#[ clap( subcommand) ]
10
- cmd : Command
10
+ cmd : Command ,
11
11
}
12
12
13
13
#[ derive( clap:: Parser ) ]
14
14
enum Command {
15
15
/// Initialize a config file for this repository.
16
- Init
16
+ Init ,
17
17
}
18
18
19
19
fn main ( ) -> anyhow:: Result < ( ) > {
Original file line number Diff line number Diff line change
1
+ use crate :: utils:: check_output;
2
+ use std:: path:: PathBuf ;
3
+
4
+ pub struct JoshProxy {
5
+ path : PathBuf ,
6
+ }
7
+
8
+ impl JoshProxy {
9
+ /// Tries to figure out if `josh-proxy` is installed.
10
+ pub fn lookup ( ) -> Option < Self > {
11
+ which:: which ( "josh-proxy" ) . ok ( ) . map ( |path| Self { path } )
12
+ }
13
+ }
14
+
15
+ fn install_josh ( ) -> Option < JoshProxy > {
16
+ check_output ( & [
17
+ "cargo" ,
18
+ "install" ,
19
+ "--locked" ,
20
+ "--git" ,
21
+ "https://github.com/josh-project/josh" ,
22
+ "--tag" ,
23
+ "r24.10.04" ,
24
+ ] ) ;
25
+ JoshProxy :: lookup ( )
26
+ }
Original file line number Diff line number Diff line change
1
+ pub mod josh;
2
+ mod utils;
3
+
1
4
#[ derive( serde:: Serialize , serde:: Deserialize ) ]
2
5
pub struct JoshConfig {
3
6
#[ serde( default = "default_org" ) ]
4
7
pub org : String ,
5
8
pub repo : String ,
6
9
/// Last SHA of rust-lang/rust that was pulled into this subtree.
7
10
#[ serde( default ) ]
8
- pub upstream_sha : Option < String >
11
+ pub upstream_sha : Option < String > ,
9
12
}
10
13
11
14
fn default_org ( ) -> String {
Original file line number Diff line number Diff line change
1
+ use std:: process:: { Command , Stdio } ;
2
+
3
+ /// Run a command from an array, collecting its output.
4
+ pub fn check_output < ' a , Args : AsRef < [ & ' a str ] > > ( l : Args ) -> String {
5
+ let l = l. as_ref ( ) ;
6
+ check_output_cfg ( l[ 0 ] , |c| c. args ( & l[ 1 ..] ) )
7
+ }
8
+
9
+ /// [`read`] with configuration. All shell helpers print the command and pass stderr.
10
+ fn check_output_cfg ( prog : & str , f : impl FnOnce ( & mut Command ) -> & mut Command ) -> String {
11
+ let mut cmd = Command :: new ( prog) ;
12
+ cmd. stderr ( Stdio :: inherit ( ) ) ;
13
+ f ( & mut cmd) ;
14
+ eprintln ! ( "+ {cmd:?}" ) ;
15
+ let out = cmd. output ( ) . expect ( "command failed" ) ;
16
+ let stdout = String :: from_utf8_lossy ( out. stdout . trim_ascii ( ) ) . to_string ( ) ;
17
+ if !out. status . success ( ) {
18
+ panic ! (
19
+ "Command `{cmd:?}` failed with exit code {:?}. STDOUT:\n {stdout}" ,
20
+ out. status. code( )
21
+ ) ;
22
+ }
23
+ stdout
24
+ }
You can’t perform that action at this time.
0 commit comments