Skip to content

Commit b2d8dee

Browse files
authored
Merge pull request #20 from Kobzol/verbose-flag
Implement verbose flag
2 parents 5a8fe26 + f031962 commit b2d8dee

File tree

4 files changed

+157
-85
lines changed

4 files changed

+157
-85
lines changed

src/bin/rustc_josh_sync.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ enum Command {
4646
/// If you instead want to exit successfully in that case, pass this flag.
4747
#[clap(long)]
4848
allow_noop: bool,
49+
50+
/// Print executed commands.
51+
#[clap(long, short = 'v')]
52+
verbose: bool,
4953
},
5054
/// Push changes into the main `rust-lang/rust` repository `branch` of a `rustc` fork under
5155
/// the given GitHub `username`.
@@ -64,6 +68,10 @@ enum Command {
6468

6569
/// Your GitHub usename where the fork is located
6670
username: String,
71+
72+
/// Print executed commands.
73+
#[clap(long, short = 'v')]
74+
verbose: bool,
6775
},
6876
}
6977

@@ -91,15 +99,16 @@ fn main() -> anyhow::Result<()> {
9199
}
92100
}
93101
Command::Pull {
102+
verbose,
94103
config_path,
95104
rust_version_path,
96105
upstream_repo,
97106
upstream_commit,
98107
allow_noop,
99108
} => {
100109
let ctx = load_context(&config_path, &rust_version_path)?;
101-
let josh = get_josh_proxy()?;
102-
let sync = GitSync::new(ctx.clone(), josh);
110+
let josh = get_josh_proxy(verbose)?;
111+
let sync = GitSync::new(ctx.clone(), josh, verbose);
103112
match sync.rustc_pull(upstream_repo, upstream_commit) {
104113
Ok(result) => {
105114
if !maybe_create_gh_pr(
@@ -121,6 +130,9 @@ fn main() -> anyhow::Result<()> {
121130
}
122131
Err(RustcPullError::PullFailed(error)) => {
123132
eprintln!("Pull failure: {error:?}");
133+
if !verbose {
134+
eprintln!("Rerun with `-v` to see executed commands");
135+
}
124136
std::process::exit(1);
125137
}
126138
}
@@ -130,16 +142,24 @@ fn main() -> anyhow::Result<()> {
130142
branch,
131143
config_path,
132144
rust_version_path,
145+
verbose,
133146
} => {
134147
let ctx = load_context(&config_path, &rust_version_path)?;
135-
let josh = get_josh_proxy()?;
136-
let sync = GitSync::new(ctx.clone(), josh);
137-
sync.rustc_push(&username, &branch)
138-
.context("cannot perform push")?;
148+
let josh = get_josh_proxy(verbose)?;
149+
let sync = GitSync::new(ctx.clone(), josh, verbose);
150+
if let Err(error) = sync
151+
.rustc_push(&username, &branch)
152+
.context("cannot perform push")
153+
{
154+
if !verbose {
155+
eprintln!("Rerun with `-v` to see executed commands");
156+
}
157+
return Err(error);
158+
}
139159

140160
// Open PR with `subtree update` title to silence the `no-merges` triagebot check
141161
let title = format!("{} subtree update", ctx.config.repo);
142-
let head = get_current_head_sha()?;
162+
let head = get_current_head_sha(verbose)?;
143163

144164
let merge_msg = format!(
145165
r#"Subtree update of `{repo}` to https://github.com/{full_repo}/commit/{head}.
@@ -204,9 +224,9 @@ fn maybe_create_gh_pr(repo: &str, title: &str, description: &str) -> anyhow::Res
204224
}
205225
}
206226

207-
fn get_josh_proxy() -> anyhow::Result<JoshProxy> {
227+
fn get_josh_proxy(verbose: bool) -> anyhow::Result<JoshProxy> {
208228
println!("Updating/installing josh-proxy binary...");
209-
match try_install_josh() {
229+
match try_install_josh(verbose) {
210230
Some(proxy) => Ok(proxy),
211231
None => Err(anyhow::anyhow!("Could not install josh-proxy")),
212232
}

src/josh.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,20 @@ impl JoshProxy {
6363
}
6464

6565
/// Try to install (or update) josh-proxy, to make sure that we use the correct version.
66-
pub fn try_install_josh() -> Option<JoshProxy> {
67-
run_command(&[
68-
"cargo",
69-
"install",
70-
"--locked",
71-
"--git",
72-
"https://github.com/josh-project/josh",
73-
"--tag",
74-
JOSH_VERSION,
75-
"josh-proxy",
76-
])
66+
pub fn try_install_josh(verbose: bool) -> Option<JoshProxy> {
67+
run_command(
68+
&[
69+
"cargo",
70+
"install",
71+
"--locked",
72+
"--git",
73+
"https://github.com/josh-project/josh",
74+
"--tag",
75+
JOSH_VERSION,
76+
"josh-proxy",
77+
],
78+
verbose,
79+
)
7780
.expect("cannot install josh-proxy");
7881
JoshProxy::lookup()
7982
}

0 commit comments

Comments
 (0)