Skip to content

Commit

Permalink
generate-shell-completion: slight refactor
Browse files Browse the repository at this point in the history
The next commit will be easier to do in the `uv-cli` crate since it
explicitly depends on `clap-complete`.
  • Loading branch information
ilyagr committed Sep 12, 2024
1 parent f22e5ef commit 1e356e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::str::FromStr;
use anyhow::{anyhow, Result};
use clap::builder::styling::{AnsiColor, Effects, Style};
use clap::builder::Styles;
use clap::{Args, Parser, Subcommand};
use clap::{Args, CommandFactory, Parser, Subcommand};
use distribution_types::{FlatIndexLocation, IndexUrl};
use pep508_rs::Requirement;
use pypi_types::VerbatimParsedUrl;
Expand Down Expand Up @@ -4234,3 +4234,10 @@ pub struct DisplayTreeArgs {
#[arg(long, alias = "reverse")]
pub invert: bool,
}

pub fn generate_shell_completion(
shell: &clap_complete_command::Shell,
buffer: &mut dyn std::io::Write,
) {
shell.generate(&mut Cli::command(), buffer);
}
4 changes: 2 additions & 2 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::process::ExitCode;
use anstream::eprintln;
use anyhow::Result;
use clap::error::{ContextKind, ContextValue};
use clap::{CommandFactory, Parser};
use clap::Parser;
use owo_colors::OwoColorize;
use settings::PipTreeSettings;
use tracing::{debug, instrument};
Expand Down Expand Up @@ -773,7 +773,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
Ok(ExitStatus::Success)
}
Commands::GenerateShellCompletion(args) => {
args.shell.generate(&mut Cli::command(), &mut stdout());
uv_cli::generate_shell_completion(&args.shell, &mut stdout());
Ok(ExitStatus::Success)
}
Commands::Tool(ToolNamespace {
Expand Down

0 comments on commit 1e356e2

Please sign in to comment.