Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature-gate command line completions #1486

Merged
merged 1 commit into from
Feb 15, 2023
Merged
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
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