Skip to content

Commit

Permalink
Add flag to generate shell completions
Browse files Browse the repository at this point in the history
  • Loading branch information
kpcyrd committed Jan 11, 2024
1 parent 674e1b2 commit 74267c9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async-channel = "1.9.0"
async-trait = "0.1.73"
chrono = { version = "0.4.31", features = ["serde"] }
clap = { version = "4.4.4", features = ["derive"] }
clap_complete = "4.4.6"
ctor = "0.2.4"
ctrlc = "3.4.1"
indexmap = { version = "2.0.1", features = ["serde"] }
Expand Down
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::env;
use std::io;
use std::time;

use clap::Parser;
use clap::{CommandFactory, Parser};
use creds::Credentials;

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

fn setup() -> Result<Options, session::Error> {
print!(
"{} v{}\n\n",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION")
);

if env::var_os("RUST_LOG").is_none() {
// set `RUST_LOG=debug` to see debug logs
env::set_var("RUST_LOG", "info,blocking=off,pavao=off,fast_socks5=off");
Expand All @@ -38,6 +33,11 @@ fn setup() -> Result<Options, session::Error> {

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

if let Some(shell) = options.generate_completions {
clap_complete::generate(shell, &mut Options::command(), "legba", &mut io::stdout());
std::process::exit(0);
}

// list plugins and exit
if options.list_plugins {
plugins::manager::list();
Expand Down
5 changes: 5 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ pub(crate) struct Options {
#[clap(short = 'Q', long, default_value_t = false)]
pub quiet: bool,

/// Generate shell completions
#[clap(long)]
#[serde(skip)]
pub generate_completions: Option<clap_complete::Shell>,

#[clap(flatten, next_help_heading = "COMMAND (CMD)")]
pub cmd: crate::plugins::cmd::options::Options,
#[cfg(feature = "amqp")]
Expand Down

0 comments on commit 74267c9

Please sign in to comment.