Skip to main content

git_filter_tree/
cli.rs

1use clap::{Args, Parser};
2
3/// Arguments for filtering a Git tree by gitattributes-style patterns.
4/// Defined here so it can be re-used as a subcommand in the porcelain `git-rewrite` CLI.
5#[derive(Args, Clone)]
6pub struct FilterTreeArgs {
7    /// Tree-ish reference (commit, branch, tag, or tree SHA)
8    pub treeish: String,
9
10    /// Gitattributes-style patterns to filter tree entries
11    #[arg(required = true)]
12    pub patterns: Vec<String>,
13
14    /// Output format
15    #[arg(short, long, value_enum, default_value = "tree-sha")]
16    pub format: OutputFormat,
17}
18
19#[derive(Parser)]
20#[command(name = "git filter-tree", bin_name = "git filter-tree")]
21#[command(author, version, about = "Filter Git tree entries by gitattributes-style patterns", long_about = None)]
22pub struct Cli {
23    #[command(flatten)]
24    pub args: FilterTreeArgs,
25}
26
27#[derive(Clone, Copy, clap::ValueEnum)]
28pub enum OutputFormat {
29    /// Output only the tree SHA
30    TreeSha,
31    /// Output tree entries (name and type)
32    Entries,
33    /// Output detailed tree information
34    Detailed,
35}