Skip to content

Commit

Permalink
Simplify command-line options declaration (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 23, 2022
1 parent bc89fc7 commit f790a55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 39 deletions.
44 changes: 11 additions & 33 deletions src/plumbing/options.rs
Expand Up @@ -37,14 +37,14 @@ pub struct Args {
pub format: core::OutputFormat,

/// The object format to assume when reading files that don't inherently know about it, or when writing files.
#[clap(long, default_value = "sha1", possible_values(&["sha1"]))]
#[clap(long, default_value_t = git_repository::hash::Kind::default(), possible_values(&["SHA1"]))]
pub object_hash: git_repository::hash::Kind,

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

#[derive(Debug, clap::Parser)]
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Subcommands for interacting with packs and their indices.
#[clap(subcommand)]
Expand All @@ -68,10 +68,9 @@ pub enum Subcommands {
pub mod pack {
use std::{ffi::OsString, path::PathBuf};

use clap::AppSettings;
use gitoxide_core as core;

#[derive(Debug, clap::Parser)]
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Subcommands for interacting with pack indices (.idx)
#[clap(subcommand)]
Expand All @@ -80,7 +79,6 @@ pub mod pack {
#[clap(subcommand)]
MultiIndex(multi_index::Subcommands),
/// Create a new pack with a set of objects.
#[clap(setting = AppSettings::DisableVersionFlag)]
Create {
#[clap(long, short = 'r')]
/// the directory containing the '.git' repository from which objects should be read.
Expand Down Expand Up @@ -140,7 +138,6 @@ pub mod pack {
tips: Vec<OsString>,
},
/// Use the git-protocol to receive a pack, emulating a clone.
#[clap(setting = AppSettings::DisableVersionFlag)]
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
Receive {
/// The protocol version to use. Valid values are 1 and 2
Expand Down Expand Up @@ -173,7 +170,6 @@ pub mod pack {
///
/// Note that this effectively removes delta compression for an average compression of 2x, creating one file per object in the process.
/// Thus this should only be done to dissolve small packs after a fetch.
#[clap(setting = AppSettings::DisableVersionFlag)]
Explode {
#[clap(long)]
/// Read written objects back and assert they match their source. Fail the operation otherwise.
Expand Down Expand Up @@ -211,7 +207,6 @@ pub mod pack {
object_path: Option<PathBuf>,
},
/// Verify the integrity of a pack, index or multi-index file
#[clap(setting = AppSettings::DisableVersionFlag)]
Verify {
#[clap(flatten)]
args: VerifyOptions,
Expand Down Expand Up @@ -257,18 +252,14 @@ pub mod pack {
pub mod multi_index {
use std::path::PathBuf;

use clap::AppSettings;

#[derive(Debug, clap::Parser)]
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Verify a multi-index quickly without inspecting objects themselves
#[clap(setting = AppSettings::DisableVersionFlag)]
Verify {
/// The path to the multi-pack-index to verify.
multi_index_path: PathBuf,
},
/// Create a multi-pack index from one or more pack index files
#[clap(setting = AppSettings::DisableVersionFlag)]
Create {
/// The path to which the multi-index file should be written, overwriting any possibly existing file.
///
Expand All @@ -287,13 +278,11 @@ pub mod pack {
pub mod index {
use std::path::PathBuf;

use clap::AppSettings;
use gitoxide_core as core;

#[derive(Debug, clap::Parser)]
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// create a pack index from a pack data file.
#[clap(setting = AppSettings::DisableVersionFlag)]
Create {
/// Specify how to iterate the pack, defaults to 'verify'
///
Expand Down Expand Up @@ -331,13 +320,10 @@ pub mod pack {
pub mod repo {
use std::path::PathBuf;

use clap::AppSettings;

#[derive(Debug, clap::Parser)]
#[derive(Debug, clap::Subcommand)]
#[clap(alias = "repo")]
pub enum Subcommands {
/// Verify the integrity of the entire repository
#[clap(setting = AppSettings::DisableVersionFlag)]
Verify {
#[clap(flatten)]
args: super::pack::VerifyOptions,
Expand All @@ -351,19 +337,16 @@ pub mod repo {
pub mod index {
use std::path::PathBuf;

use clap::AppSettings;

#[derive(Debug, clap::Parser)]
#[derive(Debug, clap::Subcommand)]
#[clap(alias = "index")]
pub enum Subcommands {
/// Print all entries to standard output
#[clap(setting = AppSettings::DisableVersionFlag)]
Entries {
/// The object format to assume when reading files that don't inherently know about it, or when writing files.
#[clap(long, default_value = "sha1", possible_values(&["sha1"]))]
#[clap(long, default_value_t = git_repository::hash::Kind::default(), possible_values(&["SHA1"]))]
object_hash: git_repository::hash::Kind,

/// The path too the index file.
/// The path to the index file.
index_path: PathBuf,
},
}
Expand All @@ -373,12 +356,9 @@ pub mod index {
pub mod commitgraph {
use std::path::PathBuf;

use clap::AppSettings;

#[derive(Debug, clap::Parser)]
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Verify the integrity of a commit graph
#[clap(setting = AppSettings::DisableVersionFlag)]
Verify {
/// The path to '.git/objects/info/', '.git/objects/info/commit-graphs/', or '.git/objects/info/commit-graph' to validate.
#[clap(parse(from_os_str))]
Expand All @@ -393,16 +373,14 @@ pub mod commitgraph {
///
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
pub mod remote {
use clap::AppSettings;
use gitoxide_core as core;

#[derive(Debug, clap::Parser)]
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// List remote references from a remote identified by a url.
///
/// This is the plumbing equivalent of `git ls-remote`.
/// Supported URLs are documented here: <https://www.git-scm.com/docs/git-clone#_git_urls>
#[clap(setting = AppSettings::DisableVersionFlag)]
RefList {
/// The protocol version to use. Valid values are 1 and 2
#[clap(long, short = 'p')]
Expand Down
9 changes: 3 additions & 6 deletions src/porcelain/options.rs
Expand Up @@ -24,11 +24,10 @@ pub struct Args {
pub cmd: Subcommands,
}

#[derive(Debug, clap::Parser)]
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Initialize the repository in the current directory.
#[clap(visible_alias = "initialize")]
#[clap(setting = AppSettings::DisableVersionFlag)]
Init {
/// The directory in which to initialize a new git repository.
///
Expand All @@ -44,20 +43,18 @@ pub enum Subcommands {
}

#[cfg(feature = "gitoxide-core-tools")]
#[derive(Debug, clap::Parser)]
#[clap(setting = AppSettings::DisableVersionFlag, setting = AppSettings::SubcommandRequired)]
#[derive(Debug, clap::Subcommand)]
#[clap(setting = AppSettings::SubcommandRequired)]
#[clap(visible_alias = "t")]
pub enum ToolCommands {
/// Find all repositories in a given directory.
#[clap(setting = AppSettings::DisableVersionFlag)]
Find {
/// The directory in which to find all git repositories.
///
/// Defaults to the current working directory.
root: Option<PathBuf>,
},
/// Move all repositories found in a directory into a structure matching their clone URLs.
#[clap(setting = AppSettings::DisableVersionFlag)]
Organize {
#[clap(long)]
/// The operation will be in dry-run mode unless this flag is set.
Expand Down

0 comments on commit f790a55

Please sign in to comment.