Skip to content

Commit

Permalink
Merge pull request #1486 from messense/feature-gate-completion
Browse files Browse the repository at this point in the history
Feature-gate command line completions
  • Loading branch information
messense authored Feb 15, 2023
2 parents 93f502a + eea17ae commit 4291042
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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"]
Expand Down
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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;

Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 4291042

Please sign in to comment.