Skip to content

Commit

Permalink
Move common flags to common plac
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 6, 2020
1 parent ed5882d commit c0352c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 66 deletions.
19 changes: 5 additions & 14 deletions src/plumbing/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ mod options {
/// print the program version.
pub version: bool,

/// display verbose messages and progress information
#[argh(switch, short = 'v')]
pub verbose: bool,

#[argh(option, short = 't')]
/// the amount of threads to use for some operations.
///
Expand All @@ -34,10 +38,6 @@ mod options {
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "index-from-pack")]
pub struct IndexFromPack {
/// display verbose messages and progress information
#[argh(switch, short = 'v')]
pub verbose: bool,

/// specify how to iterate the pack, defaults to 'verify'
///
/// Valid values are
Expand Down Expand Up @@ -79,10 +79,6 @@ mod options {
#[argh(switch)]
pub delete_pack: bool,

/// display verbose messages and progress information
#[argh(switch, short = 'v')]
pub verbose: bool,

/// compress bytes even when using the sink, i.e. no object directory is specified
///
/// This helps to determine overhead related to compression. If unset, the sink will
Expand Down Expand Up @@ -139,9 +135,6 @@ mod options {
/// output statistical information about the pack
#[argh(switch, short = 's')]
pub statistics: bool,
/// display verbose messages and progress information
#[argh(switch, short = 'v')]
pub verbose: bool,
/// the '.pack' or '.idx' file whose checksum to validate.
#[argh(positional)]
pub path: PathBuf,
Expand Down Expand Up @@ -188,9 +181,9 @@ pub fn main() -> Result<()> {
pub use options::*;
let cli: Args = crate::shared::from_env();
let thread_limit = cli.threads;
let verbose = cli.verbose;
match cli.subcommand {
SubCommands::IndexFromPack(IndexFromPack {
verbose,
iteration_mode,
pack_path,
directory,
Expand All @@ -210,7 +203,6 @@ pub fn main() -> Result<()> {
pack_path,
sink_compress,
object_path,
verbose,
verify,
check,
delete_pack,
Expand All @@ -231,7 +223,6 @@ pub fn main() -> Result<()> {
}
SubCommands::PackVerify(PackVerify {
path,
verbose,
statistics,
algorithm,
decode,
Expand Down
69 changes: 18 additions & 51 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ mod options {
/// If unset, or the value is 0, there is no limit and all logical cores can be used.
pub threads: Option<usize>,

/// Display verbose messages and progress information
#[structopt(long, short = "v")]
pub verbose: bool,

/// Bring up a terminal user interface displaying progress visually
#[structopt(long, conflicts_with("verbose"))]
pub progress: bool,

/// The progress TUI will stay up even though the work is already completed.
///
/// Use this to be able to read progress messages or additional information visible in the TUI log pane.
#[structopt(long, conflicts_with("verbose"), requires("progress"))]
pub progress_keep_open: bool,

#[structopt(subcommand)]
pub cmd: Subcommands,
}
Expand All @@ -32,20 +46,6 @@ mod options {
/// This command can also be used to stream packs to standard input or to repair partial packs.
#[structopt(setting = AppSettings::ColoredHelp)]
IndexFromPack {
/// Display verbose messages and progress information
#[structopt(long, short = "v")]
verbose: bool,

/// Bring up a terminal user interface displaying progress visually
#[structopt(long, conflicts_with("verbose"))]
progress: bool,

/// The progress TUI will stay up even though the work is already completed.
///
/// Use this to be able to read progress messages or additional information visible in the TUI log pane.
#[structopt(long, conflicts_with("verbose"), requires("progress"))]
progress_keep_open: bool,

/// Specify how to iterate the pack, defaults to 'verify'
///
/// Valid values are
Expand Down Expand Up @@ -105,20 +105,6 @@ mod options {
#[structopt(long)]
sink_compress: bool,

/// Display verbose messages and progress information
#[structopt(long, short = "v")]
verbose: bool,

/// Bring up a terminal user interface displaying progress visually
#[structopt(long, conflicts_with("verbose"))]
progress: bool,

/// The progress TUI will stay up even though the work is already completed.
///
/// Use this to be able to read progress messages or additional information visible in the TUI log pane.
#[structopt(long, conflicts_with("verbose"), requires("progress"))]
progress_keep_open: bool,

/// The '.pack' or '.idx' file to explode into loose objects
#[structopt(parse(from_os_str))]
pack_path: PathBuf,
Expand Down Expand Up @@ -151,14 +137,6 @@ mod options {
)]
algorithm: core::pack::verify::Algorithm,

/// Display verbose messages and progress information
#[structopt(long, short = "v")]
verbose: bool,

/// Bring up a terminal user interface displaying progress visually
#[structopt(long, conflicts_with("verbose"))]
progress: bool,

#[structopt(long, conflicts_with("re-encode"))]
/// Decode and parse tags, commits and trees to validate their correctness beyond hashing correctly.
///
Expand All @@ -175,12 +153,6 @@ mod options {
/// owned objects, causing plenty of allocation to occour.
re_encode: bool,

/// The progress TUI will stay up even though the work is already completed.
///
/// Use this to be able to read progress messages or additional information visible in the TUI log pane.
#[structopt(long, conflicts_with("verbose"), requires("progress"))]
progress_keep_open: bool,

/// The '.pack' or '.idx' file whose checksum to validate.
#[structopt(parse(from_os_str))]
path: PathBuf,
Expand Down Expand Up @@ -292,14 +264,15 @@ fn prepare_and_run<T: Send + 'static>(
pub fn main() -> Result<()> {
let args = Args::from_args();
let thread_limit = args.threads;
let verbose = args.verbose;
let progress = args.progress;
let progress_keep_open = args.progress_keep_open;

match args.cmd {
Subcommands::IndexFromPack {
verbose,
iteration_mode,
pack_path,
directory,
progress,
progress_keep_open,
} => prepare_and_run(
"index-from-pack",
verbose,
Expand All @@ -318,10 +291,7 @@ pub fn main() -> Result<()> {
},
),
Subcommands::PackExplode {
verbose,
check,
progress,
progress_keep_open,
sink_compress,
delete_pack,
pack_path,
Expand Down Expand Up @@ -350,12 +320,9 @@ pub fn main() -> Result<()> {
Subcommands::PackVerify {
path,
algorithm,
verbose,
progress,
format,
decode,
re_encode,
progress_keep_open,
statistics,
} => prepare_and_run(
"pack-verify",
Expand Down
2 changes: 1 addition & 1 deletion tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* [x] for pretty mode
* [x] allow interrupting the resolution phase too
* [x] fix typo :D - thanks IJ for confusing me
* [ ] move --verbose, --progress and --progress-keep-open to the top-level
* [x] move --verbose, --progress and --progress-keep-open to the top-level
* [ ] unit tests for bundle index write
* [ ] journey test for command-line capabilities
* [ ] nicer errors with descriptive messages
Expand Down

0 comments on commit c0352c2

Please sign in to comment.