Skip to content
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
19 changes: 10 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ cfg-if = { version = "1.0.3", default-features = false }
chrono = { version = "0.4.41", default-features = false, features = ["clock", "serde"] }
chrono-tz = { version = "0.10.4", default-features = false, features = ["serde"] }
clap = { version = "4.5.53", default-features = false, features = ["derive", "error-context", "env", "help", "std", "string", "usage", "wrap_help"] }
clap_complete = "4.5.65"
colored = { version = "3.0.0", default-features = false }
crossbeam-utils = { version = "0.8.21", default-features = false }
darling = { version = "0.20.11", default-features = false, features = ["suggestions"] }
Expand Down Expand Up @@ -210,6 +211,7 @@ serial_test = { version = "3.2" }
[dependencies]
cfg-if.workspace = true
clap.workspace = true
clap_complete.workspace = true
indoc.workspace = true
paste.workspace = true
pin-project.workspace = true
Expand Down
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ cidr,https://github.com/stbuehler/rust-cidr,MIT,Stefan Bühler <stbuehler@web.de
cipher,https://github.com/RustCrypto/traits,MIT OR Apache-2.0,RustCrypto Developers
clap,https://github.com/clap-rs/clap,MIT OR Apache-2.0,The clap Authors
clap_builder,https://github.com/clap-rs/clap,MIT OR Apache-2.0,The clap_builder Authors
clap_complete,https://github.com/clap-rs/clap,MIT OR Apache-2.0,The clap_complete Authors
clap_derive,https://github.com/clap-rs/clap,MIT OR Apache-2.0,The clap_derive Authors
clap_lex,https://github.com/clap-rs/clap,MIT OR Apache-2.0,The clap_lex Authors
clipboard-win,https://github.com/DoumanAsh/clipboard-win,BSL-1.0,Douman <douman@gmx.se>
Expand Down
3 changes: 3 additions & 0 deletions changelog.d/24414_shell_autocompletion.enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Autocompletion scripts for the vector cli can now be generated via `vector completion <SHELL>`.

authors: weriomat
9 changes: 7 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::tap;
use crate::top;

use crate::{
config, convert_config, generate, generate_schema, get_version, graph, list, signal, unit_test,
validate,
completion, config, convert_config, generate, generate_schema, get_version, graph, list,
signal, unit_test, validate,
};

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -318,6 +318,10 @@ pub enum SubCommand {
/// By default all output is writen to stdout. The `output_path` option can be used to redirect to a file.
GenerateSchema(generate_schema::Opts),

/// Generate shell completion, then exit.
#[command(hide = true)]
Completion(completion::Opts),

/// Output a provided Vector configuration file/dir as a single JSON object, useful for checking in to version control.
#[command(hide = true)]
Config(config::Opts),
Expand Down Expand Up @@ -355,6 +359,7 @@ impl SubCommand {
color: bool,
) -> exitcode::ExitCode {
match self {
Self::Completion(s) => completion::cmd(s),
Self::Config(c) => config::cmd(c),
Self::ConvertConfig(opts) => convert_config::cmd(opts),
Self::Generate(g) => generate::cmd(g),
Expand Down
23 changes: 23 additions & 0 deletions src/completion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![allow(missing_docs)]
use clap::{CommandFactory, Parser};
use clap_complete::{Shell, generate};
use std::io;

use crate::cli::Opts as RootCli;

#[derive(Parser, Debug, Clone)]
#[command(rename_all = "kebab-case")]
pub struct Opts {
/// Shell to generate completion for
#[clap(value_enum)]
shell: Shell,
}

pub fn cmd(opts: &Opts) -> exitcode::ExitCode {
let mut cmd = RootCli::command();
let bin_name = cmd.get_name().to_string();

generate(opts.shell, &mut cmd, bin_name, &mut io::stdout());

exitcode::OK
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub mod aws;
#[allow(unreachable_pub)]
pub mod codecs;
pub mod common;
pub mod completion;
mod convert_config;
pub mod encoding_transcode;
pub mod enrichment_tables;
Expand Down
2 changes: 1 addition & 1 deletion vdev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ anyhow.workspace = true
chrono.workspace = true
clap.workspace = true
clap-verbosity-flag = "3.0.4"
clap_complete = "4.5.64"
clap_complete.workspace = true
directories = "6.0.0"
glob.workspace = true
hex = "0.4.3"
Expand Down
Loading