Skip to content

Commit

Permalink
ditch structopt in favor of clap 3.0 beta1
Browse files Browse the repository at this point in the history
It's bascially the same, but should make getting size improvements
way easier.
Byron committed Aug 6, 2020

Verified

This commit was signed with the committer’s verified signature.
Byron Sebastian Thiel
1 parent 0a4b0f3 commit d7591e2
Showing 5 changed files with 108 additions and 75 deletions.
93 changes: 62 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ light = ["fast", "lean-cli", "git-features/interruptible"]
small = ["lean-cli"]

fast = ["git-features/parallel", "git-features/fast-sha1"]
pretty-cli = ["structopt",
pretty-cli = ["clap",
"git-features/progress-prodash",
"git-features/interruptible",
"gitoxide-core/serde1",
@@ -61,7 +61,7 @@ anyhow = "1.0.31"
gitoxide-core = { version = "0.1.0", path = "gitoxide-core" }
git-features = { version = "^0.2.0", path = "git-features" }

structopt = { version = "0.3.14", optional = true }
clap = { version = "3.0.0-beta.1", optional = true }
argh = { version = "0.1.3", optional = true, default-features = false }
prodash = { version = "7.0.2", optional = true, default-features = false }
atty = { version = "0.2.14", optional = true, default-features = false }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -245,7 +245,7 @@ The top-level command-line interface.
* If disabled, the binary will be visibly smaller.
* _(mutually exclusive)_
* **pretty-cli**
* Use `clap` + `structopt` to build the prettiest, best documented and most user-friendly CLI at the expense of file size.
* Use `clap` 3.0 to build the prettiest, best documented and most user-friendly CLI at the expense of file size.
* provides a terminal user interface for detailed and exhaustive progress.
* provides a line renderer for log-like progress
* **lean-cli**
63 changes: 32 additions & 31 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
use anyhow::{anyhow, Result};
use clap::Clap;
use gitoxide_core as core;
use std::io::{stderr, stdout, Write};
use structopt::StructOpt;

use gitoxide_core::pack::verify;
use options::*;

mod options {
use clap::{AppSettings, Clap};
use gitoxide_core as core;
use std::path::PathBuf;
use structopt::{clap::AppSettings, StructOpt};

#[derive(Debug, StructOpt)]
#[structopt(name = "gix-plumbing", about = "The git underworld")]
#[structopt(settings = &[AppSettings::SubcommandRequired, AppSettings::ColoredHelp])]
#[derive(Debug, Clap)]
#[clap(name = "gix-plumbing", about = "The git underworld")]
#[clap(setting = AppSettings::SubcommandRequired)]
#[clap(setting = AppSettings::ColoredHelp)]
pub struct Args {
#[structopt(long, short = "t")]
#[clap(long, short = "t")]
/// The amount of threads to use for some operations.
///
/// 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")]
#[clap(long, short = "v")]
pub verbose: bool,

/// Bring up a terminal user interface displaying progress visually
#[structopt(long, conflicts_with("verbose"))]
#[clap(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"))]
#[clap(long, conflicts_with("verbose"), requires("progress"))]
pub progress_keep_open: bool,

#[structopt(subcommand)]
#[clap(subcommand)]
pub cmd: Subcommands,
}

#[derive(Debug, StructOpt)]
#[derive(Debug, Clap)]
pub enum Subcommands {
/// Create an index from a packfile.
///
/// This command can also be used to stream packs to standard input or to repair partial packs.
#[structopt(setting = AppSettings::ColoredHelp)]
#[clap(setting = AppSettings::ColoredHelp)]
IndexFromPack {
/// Specify how to iterate the pack, defaults to 'verify'
///
@@ -55,7 +56,7 @@ mod options {
/// * the input ourselves and validate that it matches with the hash provided in the pack
/// - restore
/// * hash the input ourselves and ignore failing entries, instead finish the pack with the hash we computed
#[structopt(
#[clap(
long,
short = "i",
default_value = "verify",
@@ -66,30 +67,30 @@ mod options {
/// Path to the pack file to read (with .pack extension).
///
/// If unset, the pack file is expected on stdin.
#[structopt(long, short = "p")]
#[clap(long, short = "p")]
pack_path: Option<PathBuf>,

/// The folder into which to place the pack and the generated index file
///
/// If unset, only informational output will be provided to standard output.
#[structopt(parse(from_os_str))]
#[clap(parse(from_os_str))]
directory: Option<PathBuf>,
},
/// Verify the integrity of a pack or index file
#[structopt(setting = AppSettings::ColoredHelp)]
#[clap(setting = AppSettings::ColoredHelp)]
PackExplode {
#[structopt(long)]
#[clap(long)]
/// Read written objects back and assert they match their source. Fail the operation otherwise.
///
/// Only relevant if an object directory is set.
verify: bool,

/// delete the pack and index file after the operation is successful
#[structopt(long)]
#[clap(long)]
delete_pack: bool,

/// The amount of checks to run
#[structopt(
#[clap(
long,
short = "c",
default_value = "all",
@@ -102,25 +103,25 @@ mod options {
/// This helps to determine overhead related to compression. If unset, the sink will
/// only create hashes from bytes, which is usually limited by the speed at which input
/// can be obtained.
#[structopt(long)]
#[clap(long)]
sink_compress: bool,

/// The '.pack' or '.idx' file to explode into loose objects
#[structopt(parse(from_os_str))]
#[clap(parse(from_os_str))]
pack_path: PathBuf,

/// The path into which all objects should be written. Commonly '.git/objects'
#[structopt(parse(from_os_str))]
#[clap(parse(from_os_str))]
object_path: Option<PathBuf>,
},
/// Verify the integrity of a pack or index file
#[structopt(setting = AppSettings::ColoredHelp)]
#[clap(setting = AppSettings::ColoredHelp)]
PackVerify {
/// output statistical information about the pack
#[structopt(long, short = "s")]
#[clap(long, short = "s")]
statistics: bool,
/// Determine the format to use when outputting statistics.
#[structopt(
#[clap(
long,
short = "f",
default_value = "human",
@@ -129,22 +130,22 @@ mod options {
format: core::OutputFormat,

/// The algorithm used to verify the pack. They differ in costs.
#[structopt(
#[clap(
long,
short = "a",
default_value = "less-time",
possible_values(core::pack::verify::Algorithm::variants())
)]
algorithm: core::pack::verify::Algorithm,

#[structopt(long, conflicts_with("re-encode"))]
#[clap(long, conflicts_with("re-encode"))]
/// Decode and parse tags, commits and trees to validate their correctness beyond hashing correctly.
///
/// Malformed objects should not usually occur, but could be injected on purpose or accident.
/// This will reduce overall performance.
decode: bool,

#[structopt(long)]
#[clap(long)]
/// Decode and parse tags, commits and trees to validate their correctness, and re-encode them.
///
/// This flag is primarily to test the implementation of encoding, and requires to decode the object first.
@@ -154,7 +155,7 @@ mod options {
re_encode: bool,

/// The '.pack' or '.idx' file whose checksum to validate.
#[structopt(parse(from_os_str))]
#[clap(parse(from_os_str))]
path: PathBuf,
},
}
@@ -262,7 +263,7 @@ fn prepare_and_run<T: Send + 'static>(
}

pub fn main() -> Result<()> {
let args = Args::from_args();
let args = Args::parse();
let thread_limit = args.threads;
let verbose = args.verbose;
let progress = args.progress;
@@ -285,7 +286,7 @@ pub fn main() -> Result<()> {
git_features::progress::DoOrDiscard::from(progress),
core::pack::index::Context {
thread_limit,
iteration_mode: iteration_mode,
iteration_mode,
},
)
},
21 changes: 11 additions & 10 deletions src/porcelain/pretty.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
use anyhow::Result;
use clap::Clap;
use gitoxide_core as core;
use structopt::StructOpt;

mod options {
use structopt::{clap::AppSettings, StructOpt};
use clap::{AppSettings, Clap};

#[derive(Debug, StructOpt)]
#[structopt(about = "The git")]
#[structopt(settings = &[AppSettings::SubcommandRequired, AppSettings::ColoredHelp])]
#[derive(Debug, Clap)]
#[clap(about = "The git")]
#[clap(setting = AppSettings::SubcommandRequired)]
#[clap(setting = AppSettings::ColoredHelp)]
pub struct Args {
#[structopt(subcommand)]
#[clap(subcommand)]
pub cmd: Subcommands,
}

#[derive(Debug, StructOpt)]
#[derive(Debug, Clap)]
pub enum Subcommands {
/// Initialize the repository in the current directory.
#[structopt(alias = "initialize")]
#[structopt(setting = AppSettings::ColoredHelp)]
#[clap(alias = "initialize")]
#[clap(setting = AppSettings::ColoredHelp)]
Init,
}
}

pub fn main() -> Result<()> {
use options::*;
let args = Args::from_args();
let args = Args::parse();
match args.cmd {
Subcommands::Init => core::repository::init(),
}?;

0 comments on commit d7591e2

Please sign in to comment.