8000 feat: add the ability to generate shell completions by fgimian · Pull Request #11 · bircni/git-statuses · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add the ability to generate shell completions #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exclude = ["src/tests/*"]
git2 = { version = "0.20", default-features = false, features = ["https", "ssh", "vendored-openssl"] }
walkdir = "2.5"
clap = { version = "4.5", features = ["derive"] }
clap_complete = "4.5"
anyhow = "1"
comfy-table = "7.1.4"
rayon = "1.10.0"
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
10000
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use clap::Parser;
use clap_complete::Shell;

/// Scan the given directory for Git repositories and display their status.
/// A Repository turns red if it has unpushed changes.
Expand Down Expand Up @@ -39,4 +40,7 @@ pub struct Args {
/// but in a subfolder like `repo-name/checkout`
#[arg(short, long)]
pub subdir: Option<String>,
/// Generate shell completions
#[arg(long, value_name = "SHELL")]
pub completions: Option<Shell>,
}
14 changes: 12 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::io;

use anyhow::Result;
use clap::Parser as _;
use cli::Args;
use clap::{CommandFactory as _, Parser as _};

use crate::cli::Args;

mod cli;
mod gitinfo;
Expand All @@ -15,6 +18,13 @@ fn main() -> Result<()> {
util::initialize_logger()?;

let args = Args::parse();

if let Some(shell) = args.completions {
let mut cmd = Args::command();
clap_complete::generate(shell, &mut cmd, env!("CARGO_PKG_NAME"), &mut io::stdout());
return Ok(());
}

if args.legend {
printer::print_legend();
return Ok(());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Options:
-s, --subdir <SUBDIR>
Look in a specific subdir if it exists for each folder This can be useful, if you don't checkout in a folder directly but in a subfolder like `repo-name/checkout`

--completions <SHELL>
Generate shell completions

[possible values: bash, elvish, fish, powershell, zsh]

-h, --help
Print help

Expand Down
0