Skip to content

Commit 74267c9

Browse files
committed
Add flag to generate shell completions
1 parent 674e1b2 commit 74267c9

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ async-channel = "1.9.0"
1818
async-trait = "0.1.73"
1919
chrono = { version = "0.4.31", features = ["serde"] }
2020
clap = { version = "4.4.4", features = ["derive"] }
21+
clap_complete = "4.4.6"
2122
ctor = "0.2.4"
2223
ctrlc = "3.4.1"
2324
indexmap = { version = "2.0.1", features = ["serde"] }

src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::env;
2+
use std::io;
23
use std::time;
34

4-
use clap::Parser;
5+
use clap::{CommandFactory, Parser};
56
use creds::Credentials;
67

78
#[cfg(not(windows))]
@@ -19,12 +20,6 @@ pub(crate) use crate::plugins::Plugin;
1920
pub(crate) use crate::session::Session;
2021

2122
fn setup() -> Result<Options, session::Error> {
22-
print!(
23-
"{} v{}\n\n",
24-
env!("CARGO_PKG_NAME"),
25-
env!("CARGO_PKG_VERSION")
26-
);
27-
2823
if env::var_os("RUST_LOG").is_none() {
2924
// set `RUST_LOG=debug` to see debug logs
3025
env::set_var("RUST_LOG", "info,blocking=off,pavao=off,fast_socks5=off");
@@ -38,6 +33,11 @@ fn setup() -> Result<Options, session::Error> {
3833

3934
let options: Options = Options::parse();
4035

36+
if let Some(shell) = options.generate_completions {
37+
clap_complete::generate(shell, &mut Options::command(), "legba", &mut io::stdout());
38+
std::process::exit(0);
39+
}
40+
4141
// list plugins and exit
4242
if options.list_plugins {
4343
plugins::manager::list();

src/options.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ pub(crate) struct Options {
8484
#[clap(short = 'Q', long, default_value_t = false)]
8585
pub quiet: bool,
8686

87+
/// Generate shell completions
88+
#[clap(long)]
89+
#[serde(skip)]
90+
pub generate_completions: Option<clap_complete::Shell>,
91+
8792
#[clap(flatten, next_help_heading = "COMMAND (CMD)")]
8893
pub cmd: crate::plugins::cmd::options::Options,
8994
#[cfg(feature = "amqp")]

0 commit comments

Comments
 (0)