From 56a24b8770ac290a62fcf18bde829852ab96bed8 Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 9 Jul 2021 16:03:32 +0800 Subject: [PATCH] Add a command to generate shell completions --- Changelog.md | 4 ++++ src/main.rs | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index baa6ebace..8027d37cb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) (for the cli, not for the crate). +## Unreleased + +* Add `maturin completions ` command to generate shell completions in [#586](https://github.com/PyO3/maturin/pull/586) + ## 0.11.0 - 2021-07-04 * Add support for reading metadata from [PEP 621](https://www.python.org/dev/peps/pep-0621/) project table in `pyproject.toml` in [#555](https://github.com/PyO3/maturin/pull/555) diff --git a/src/main.rs b/src/main.rs index bb5fea2f1..be660b1e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,13 +19,13 @@ use maturin::{ Metadata21, PathWriter, PlatformTag, PyProjectToml, PythonInterpreter, Target, }; use std::env; +use std::io; use std::path::PathBuf; use structopt::StructOpt; #[cfg(feature = "upload")] use { maturin::{upload, Registry, UploadError}, reqwest::Url, - std::io, }; /// Returns the password and a bool that states whether to ask for re-entering the password @@ -283,6 +283,12 @@ enum Opt { /// The commands are meant to be called from the python PEP 517 #[structopt(name = "pep517", setting = structopt::clap::AppSettings::Hidden)] Pep517(Pep517Command), + /// Generate shell completions + #[structopt(name = "completions", setting = structopt::clap::AppSettings::Hidden)] + Completions { + #[structopt(name = "SHELL", parse(try_from_str))] + shell: structopt::clap::Shell, + }, } /// Backend for the PEP 517 integration. Not for human consumption @@ -608,6 +614,9 @@ fn run() -> Result<()> { upload_ui(&files, &publish)? } + Opt::Completions { shell } => { + Opt::clap().gen_completions_to(env!("CARGO_BIN_NAME"), shell, &mut io::stdout()); + } } Ok(())