Skip to content
Closed
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
17 changes: 16 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,18 @@ 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);
// `uvx` completion
#[allow(clippy::single_match)] // Hopefully, this will be implemented for other shells as well
match shell {
clap_complete_command::Shell::Fish => {
writeln!(buffer, r#"complete -c uvx --wraps "uv tool run""#).ok();
}
_ => {}
};
}
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