From 294fbf858a9e15aa2cedd2c840386ab415437da8 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Wed, 11 Sep 2024 21:48:58 -0700 Subject: [PATCH] generate-shell-completion: slight refactor The next commit will be easier to do in the `uv-cli` crate since it explicitly depends on `clap-complete`. --- crates/uv-cli/src/lib.rs | 9 ++++++++- crates/uv/src/lib.rs | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index d1e922593ac0a..b5fa1602c9c20 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -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; @@ -4026,3 +4026,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); +} diff --git a/crates/uv/src/lib.rs b/crates/uv/src/lib.rs index e9535db71d37c..ffc0df36a5759 100644 --- a/crates/uv/src/lib.rs +++ b/crates/uv/src/lib.rs @@ -7,7 +7,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 tracing::{debug, instrument}; @@ -734,7 +734,7 @@ async fn run(cli: Cli) -> Result { 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 {