diff options
Diffstat (limited to 'src/bin/ngit/sub_commands/list.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/list.rs | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index 68a10cc..ff43bd9 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs | |||
| @@ -3,9 +3,11 @@ use std::{ | |||
| 3 | io::Write, | 3 | io::Write, |
| 4 | ops::Add, | 4 | ops::Add, |
| 5 | process::{Command, Stdio}, | 5 | process::{Command, Stdio}, |
| 6 | time::Duration, | ||
| 6 | }; | 7 | }; |
| 7 | 8 | ||
| 8 | use anyhow::{Context, Result, bail}; | 9 | use anyhow::{Context, Result, bail}; |
| 10 | use indicatif::{ProgressBar, ProgressStyle}; | ||
| 9 | use ngit::{ | 11 | use ngit::{ |
| 10 | client::{ | 12 | client::{ |
| 11 | Params, get_all_proposal_patch_pr_pr_update_events_from_cache, | 13 | Params, get_all_proposal_patch_pr_pr_update_events_from_cache, |
| @@ -39,16 +41,55 @@ use crate::{ | |||
| 39 | }; | 41 | }; |
| 40 | 42 | ||
| 41 | fn run_git_fetch(remote_name: &str) -> Result<()> { | 43 | fn run_git_fetch(remote_name: &str) -> Result<()> { |
| 42 | println!("fetching from {remote_name}..."); | 44 | let verbose = ngit::client::is_verbose(); |
| 43 | let exit_status = Command::new("git") | 45 | if verbose { |
| 46 | println!("fetching from {remote_name}..."); | ||
| 47 | } | ||
| 48 | |||
| 49 | let spinner = if verbose { | ||
| 50 | None | ||
| 51 | } else { | ||
| 52 | let pb = ProgressBar::new_spinner() | ||
| 53 | .with_style( | ||
| 54 | ProgressStyle::with_template("{spinner} {msg}") | ||
| 55 | .unwrap() | ||
| 56 | .tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈"), | ||
| 57 | ) | ||
| 58 | .with_message(format!("Fetching from {remote_name}...")); | ||
| 59 | pb.enable_steady_tick(Duration::from_millis(100)); | ||
| 60 | Some(pb) | ||
| 61 | }; | ||
| 62 | |||
| 63 | let output = Command::new("git") | ||
| 44 | .args(["fetch", remote_name]) | 64 | .args(["fetch", remote_name]) |
| 45 | .stdout(Stdio::inherit()) | 65 | .stdout(if verbose { |
| 46 | .stderr(Stdio::inherit()) | 66 | Stdio::inherit() |
| 47 | .status() | 67 | } else { |
| 68 | Stdio::piped() | ||
| 69 | }) | ||
| 70 | .stderr(if verbose { | ||
| 71 | Stdio::inherit() | ||
| 72 | } else { | ||
| 73 | Stdio::piped() | ||
| 74 | }) | ||
| 75 | .output() | ||
| 48 | .context("failed to run git fetch")?; | 76 | .context("failed to run git fetch")?; |
| 49 | 77 | ||
| 50 | if !exit_status.success() { | 78 | if let Some(spinner) = spinner { |
| 51 | bail!("git fetch {remote_name} exited with error: {exit_status}"); | 79 | spinner.finish_and_clear(); |
| 80 | } | ||
| 81 | |||
| 82 | if !output.status.success() { | ||
| 83 | if !verbose { | ||
| 84 | let stderr = String::from_utf8_lossy(&output.stderr); | ||
| 85 | if !stderr.is_empty() { | ||
| 86 | eprintln!("{stderr}"); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | bail!( | ||
| 90 | "git fetch {remote_name} exited with error: {}", | ||
| 91 | output.status | ||
| 92 | ); | ||
| 52 | } | 93 | } |
| 53 | Ok(()) | 94 | Ok(()) |
| 54 | } | 95 | } |
| @@ -297,10 +338,7 @@ fn show_proposal_details( | |||
| 297 | } | 338 | } |
| 298 | 339 | ||
| 299 | println!(); | 340 | println!(); |
| 300 | println!( | 341 | println!("To checkout: ngit checkout {}", proposal.id); |
| 301 | "To checkout: ngit checkout {}", | ||
| 302 | proposal.id | ||
| 303 | ); | ||
| 304 | println!("To apply: ngit apply {}", proposal.id); | 342 | println!("To apply: ngit apply {}", proposal.id); |
| 305 | 343 | ||
| 306 | Ok(()) | 344 | Ok(()) |