Skip to content

Commit ac490c2

Browse files
committed
attempt to implement progress with a mode enum
1 parent fa44826 commit ac490c2

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

Diff for: src/plumbing/pretty.rs

+36-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use gitoxide_core as core;
44
use std::io::{stderr, stdout, Write};
55
use structopt::StructOpt;
66

7+
use options::*;
8+
79
mod options {
810
use std::path::PathBuf;
911
use structopt::{clap::AppSettings, StructOpt};
@@ -17,6 +19,30 @@ mod options {
1719
pub cmd: Subcommands,
1820
}
1921

22+
#[derive(Debug)]
23+
pub enum ProgressMode {
24+
Stop,
25+
KeepRunning,
26+
}
27+
28+
impl ProgressMode {
29+
fn variants() -> &'static [&'static str] {
30+
&["stop", "keep-running"]
31+
}
32+
}
33+
impl std::str::FromStr for ProgressMode {
34+
type Err = String;
35+
36+
fn from_str(s: &str) -> Result<Self, Self::Err> {
37+
let s_lc = s.to_ascii_lowercase();
38+
Ok(match s_lc.as_str() {
39+
"stop" => ProgressMode::Stop,
40+
"keep-running" => ProgressMode::KeepRunning,
41+
_ => return Err(format!("Invalid progress mode: {}", s)),
42+
})
43+
}
44+
}
45+
2046
#[derive(Debug, StructOpt)]
2147
pub enum Subcommands {
2248
/// Verify the integrity of a pack or index file
@@ -31,8 +57,8 @@ mod options {
3157
verbose: bool,
3258

3359
/// if set, bring up a terminal user interface displaying progress visually
34-
#[structopt(long, conflicts_with("verbose"))]
35-
progress: bool,
60+
#[structopt(long, conflicts_with("verbose"), possible_values(ProgressMode::variants()))]
61+
progress: Option<ProgressMode>,
3662

3763
/// The '.pack' or '.idx' file whose checksum to validate.
3864
#[structopt(parse(from_os_str))]
@@ -44,24 +70,27 @@ mod options {
4470
fn init_progress(
4571
name: &str,
4672
verbose: bool,
47-
progress: bool,
73+
progress: Option<ProgressMode>,
4874
) -> (
4975
Option<JoinThreadOnDrop>,
5076
Option<progress::Either<progress::Log, prodash::tree::Item>>,
5177
) {
5278
super::init_env_logger(verbose);
5379
match (verbose, progress) {
54-
(false, false) => (None, None),
55-
(true, false) => (None, Some(progress::Either::Left(progress::Log::new(name)))),
56-
(true, true) | (false, true) => {
80+
(false, None) => (None, None),
81+
(true, None) => (None, Some(progress::Either::Left(progress::Log::new(name)))),
82+
(true, Some(mode)) | (false, Some(mode)) => {
5783
let progress = prodash::Tree::new();
5884
let sub_progress = progress.add_child(name);
5985
let render_tui = prodash::tui::render(
6086
progress,
6187
prodash::tui::TuiOptions {
6288
title: "gitoxide".into(),
6389
frames_per_second: 6.0,
64-
stop_if_empty_progress: true,
90+
stop_if_empty_progress: match mode {
91+
ProgressMode::KeepRunning => false,
92+
ProgressMode::Stop => true,
93+
},
6594
..Default::default()
6695
},
6796
)
@@ -84,7 +113,6 @@ impl Drop for JoinThreadOnDrop {
84113
}
85114

86115
pub fn main() -> Result<()> {
87-
use options::*;
88116
let args = Args::from_args();
89117
match args.cmd {
90118
Subcommands::VerifyPack {

0 commit comments

Comments
 (0)