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
2 changes: 1 addition & 1 deletion src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl GlobalArgs {
}
}

fn cli() -> App {
pub fn cli() -> App {
let is_rustup = std::env::var_os("RUSTUP_HOME").is_some();
let usage = if is_rustup {
"cargo [+toolchain] [OPTIONS] [SUBCOMMAND]"
Expand Down
26 changes: 26 additions & 0 deletions src/bin/cargo/commands/complete.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::command_prelude::*;

use clap::Shell;

pub fn cli() -> App {
subcommand("complete")
.about("Generate completion file for a shell")
.arg(
Arg::with_name("shell")
.takes_value(true)
.required(true)
.help("The shell to generate a completion file for")
)
.after_help("Run `cargo help complete` for more detailed information.\n")
}

pub fn exec(_config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let shell_name = args.value_of("shell").unwrap();
let shell: Shell = shell_name.parse()
// TODO - proper error handling
.expect(&format!("unknown shell: {}", shell_name));

crate::cli::cli().gen_completions_to("cargo", shell, &mut std::io::stdout());

Ok(())
}
3 changes: 3 additions & 0 deletions src/bin/cargo/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub fn builtin() -> Vec<App> {
build::cli(),
check::cli(),
clean::cli(),
complete::cli(),
describe_future_incompatibilities::cli(),
doc::cli(),
fetch::cli(),
Expand Down Expand Up @@ -45,6 +46,7 @@ pub fn builtin_exec(cmd: &str) -> Option<fn(&mut Config, &ArgMatches<'_>) -> Cli
"build" => build::exec,
"check" => check::exec,
"clean" => clean::exec,
"complete" => complete::exec,
"describe-future-incompatibilities" => describe_future_incompatibilities::exec,
"doc" => doc::exec,
"fetch" => fetch::exec,
Expand Down Expand Up @@ -84,6 +86,7 @@ pub mod bench;
pub mod build;
pub mod check;
pub mod clean;
pub mod complete;
pub mod describe_future_incompatibilities;
pub mod doc;
pub mod fetch;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use cargo::core::shell::Shell;
use cargo::util::{self, closest_msg, command_prelude, CargoResult, CliResult, Config};
use cargo::util::{CliError, ProcessError};

mod cli;
pub mod cli;
mod commands;

use crate::command_prelude::*;
Expand Down