diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index 5ae821550ee..a85f962dbc4 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -13,9 +13,9 @@ use git_repository::bstr::io::BufReadExt; use gitoxide_core as core; use gitoxide_core::pack::verify; -use crate::plumbing::options::{commit, mailmap, odb, revision, tree}; +use crate::plumbing::options::{commit, exclude, mailmap, odb, revision, tree}; use crate::{ - plumbing::options::{free, repo, Args, Subcommands}, + plumbing::options::{free, Args, Subcommands}, shared::pretty::prepare_and_run, }; @@ -609,42 +609,40 @@ pub fn main() -> Result<()> { move |_progress, out, err| core::repository::mailmap::entries(repository()?.into(), format, out, err), ), }, - Subcommands::Repository(repo::Platform { cmd }) => match cmd { - repo::Subcommands::Exclude { cmd } => match cmd { - repo::exclude::Subcommands::Query { - patterns, - pathspecs, - show_ignore_patterns, - } => prepare_and_run( - "repository-exclude-query", - verbose, - progress, - progress_keep_open, - None, - move |_progress, out, _err| { - use git::bstr::ByteSlice; - core::repository::exclude::query( - repository()?.into(), - if pathspecs.is_empty() { - Box::new( - stdin_or_bail()? - .byte_lines() - .filter_map(Result::ok) - .filter_map(|line| git::path::Spec::from_bytes(line.as_bstr())), - ) as Box> - } else { - Box::new(pathspecs.into_iter()) - }, - out, - core::repository::exclude::query::Options { - format, - show_ignore_patterns, - overrides: patterns, - }, - ) - }, - ), - }, + Subcommands::Exclude { cmd } => match cmd { + exclude::Subcommands::Query { + patterns, + pathspecs, + show_ignore_patterns, + } => prepare_and_run( + "repository-exclude-query", + verbose, + progress, + progress_keep_open, + None, + move |_progress, out, _err| { + use git::bstr::ByteSlice; + core::repository::exclude::query( + repository()?.into(), + if pathspecs.is_empty() { + Box::new( + stdin_or_bail()? + .byte_lines() + .filter_map(Result::ok) + .filter_map(|line| git::path::Spec::from_bytes(line.as_bstr())), + ) as Box> + } else { + Box::new(pathspecs.into_iter()) + }, + out, + core::repository::exclude::query::Options { + format, + show_ignore_patterns, + overrides: patterns, + }, + ) + }, + ), }, }?; Ok(()) diff --git a/src/plumbing/options.rs b/src/plumbing/options.rs index 9d20138cf67..e493121e12b 100644 --- a/src/plumbing/options.rs +++ b/src/plumbing/options.rs @@ -81,8 +81,11 @@ pub enum Subcommands { #[clap(subcommand)] cmd: mailmap::Subcommands, }, - /// Subcommands for interacting with entire git repositories - Repository(repo::Platform), + /// Interact with the exclude files like .gitignore. + Exclude { + #[clap(subcommand)] + cmd: exclude::Subcommands, + }, /// Subcommands that need no git repository to run. #[clap(subcommand)] Free(free::Subcommands), @@ -580,48 +583,28 @@ pub mod free { } } -/// -pub mod repo { - #[derive(Debug, clap::Parser)] - pub struct Platform { - /// Subcommands - #[clap(subcommand)] - pub cmd: Subcommands, - } +pub mod exclude { + use std::ffi::OsString; + + use git_repository as git; #[derive(Debug, clap::Subcommand)] - #[clap(visible_alias = "repo")] pub enum Subcommands { - /// Interact with the exclude files like .gitignore. - Exclude { - #[clap(subcommand)] - cmd: exclude::Subcommands, + /// Check if path-specs are excluded and print the result similar to `git check-ignore`. + Query { + /// Show actual ignore patterns instead of un-excluding an entry. + /// + /// That way one can understand why an entry might not be excluded. + #[clap(long, short = 'i')] + show_ignore_patterns: bool, + /// Additional patterns to use for exclusions. They have the highest priority. + /// + /// Useful for undoing previous patterns using the '!' prefix. + #[clap(long, short = 'p')] + patterns: Vec, + /// The git path specifications to check for exclusion, or unset to read from stdin one per line. + #[clap(parse(try_from_os_str = std::convert::TryFrom::try_from))] + pathspecs: Vec, }, } - - pub mod exclude { - use std::ffi::OsString; - - use git_repository as git; - - #[derive(Debug, clap::Subcommand)] - pub enum Subcommands { - /// Check if path-specs are excluded and print the result similar to `git check-ignore`. - Query { - /// Show actual ignore patterns instead of un-excluding an entry. - /// - /// That way one can understand why an entry might not be excluded. - #[clap(long, short = 'i')] - show_ignore_patterns: bool, - /// Additional patterns to use for exclusions. They have the highest priority. - /// - /// Useful for undoing previous patterns using the '!' prefix. - #[clap(long, short = 'p')] - patterns: Vec, - /// The git path specifications to check for exclusion, or unset to read from stdin one per line. - #[clap(parse(try_from_os_str = std::convert::TryFrom::try_from))] - pathspecs: Vec, - }, - } - } }