From eea17ae9634a43e46c5bc818195c7858d74a0997 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 15 Feb 2023 16:27:28 +0800 Subject: [PATCH] Feature-gate command line completions --- Cargo.toml | 6 ++++-- src/main.rs | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a2e65b96f..9e154e791 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,7 @@ time = "0.3.17" # cli clap = { version = "4.0.0", features = ["derive", "env", "wrap_help"] } -clap_complete_command = "0.4.0" +clap_complete_command = { version = "0.4.0", optional = true } # cross compile cargo-zigbuild = { version = "0.16.0", default-features = false, optional = true } @@ -95,10 +95,12 @@ which = "4.3.0" [features] default = ["full", "rustls"] -full = ["cross-compile", "log", "scaffolding", "upload"] +full = ["cli-completion", "cross-compile", "log", "scaffolding", "upload"] log = ["tracing-subscriber"] +cli-completion = ["dep:clap_complete_command"] + upload = ["ureq", "multipart", "configparser", "bytesize", "dialoguer/password"] # keyring doesn't support *BSD so it's not enabled in `full` by default password-storage = ["upload", "keyring"] diff --git a/src/main.rs b/src/main.rs index a18a64248..41331713c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,9 @@ use anyhow::{bail, Context, Result}; #[cfg(feature = "zig")] use cargo_zigbuild::Zig; -use clap::{CommandFactory, Parser, Subcommand}; +#[cfg(feature = "cli-completion")] +use clap::CommandFactory; +use clap::{Parser, Subcommand}; #[cfg(feature = "scaffolding")] use maturin::{ci::GenerateCI, init_project, new_project, GenerateProjectOptions}; use maturin::{ @@ -16,7 +18,6 @@ use maturin::{ #[cfg(feature = "upload")] use maturin::{upload_ui, PublishOpt}; use std::env; -use std::io; use std::path::PathBuf; use tracing::debug; @@ -157,6 +158,7 @@ enum Opt { #[command(subcommand)] Pep517(Pep517Command), /// Generate shell completions + #[cfg(feature = "cli-completion")] #[command(name = "completions", hide = true)] Completions { #[arg(value_name = "SHELL")] @@ -449,8 +451,9 @@ fn run() -> Result<()> { upload_ui(&files, &publish)? } + #[cfg(feature = "cli-completion")] Opt::Completions { shell } => { - shell.generate(&mut Opt::command(), &mut io::stdout()); + shell.generate(&mut Opt::command(), &mut std::io::stdout()); } #[cfg(feature = "zig")] Opt::Zig(subcommand) => {