From f790a55ff4263bea9b9476137bac3824912044ac Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 23 Jan 2022 20:52:41 +0800 Subject: [PATCH] Simplify command-line options declaration (#298) --- src/plumbing/options.rs | 44 ++++++++++------------------------------ src/porcelain/options.rs | 9 +++----- 2 files changed, 14 insertions(+), 39 deletions(-) diff --git a/src/plumbing/options.rs b/src/plumbing/options.rs index bdb3fcce5b..919d9d1902 100644 --- a/src/plumbing/options.rs +++ b/src/plumbing/options.rs @@ -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)] @@ -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)] @@ -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. @@ -140,7 +138,6 @@ pub mod pack { tips: Vec, }, /// 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 @@ -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. @@ -211,7 +207,6 @@ pub mod pack { object_path: Option, }, /// Verify the integrity of a pack, index or multi-index file - #[clap(setting = AppSettings::DisableVersionFlag)] Verify { #[clap(flatten)] args: VerifyOptions, @@ -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. /// @@ -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' /// @@ -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, @@ -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, }, } @@ -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))] @@ -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: - #[clap(setting = AppSettings::DisableVersionFlag)] RefList { /// The protocol version to use. Valid values are 1 and 2 #[clap(long, short = 'p')] diff --git a/src/porcelain/options.rs b/src/porcelain/options.rs index a49cd0f369..3fb403b68f 100644 --- a/src/porcelain/options.rs +++ b/src/porcelain/options.rs @@ -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. /// @@ -44,12 +43,11 @@ 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. /// @@ -57,7 +55,6 @@ pub enum ToolCommands { root: Option, }, /// 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.