Support for creating shell completions

pull/139/head
Dennis Schwerdel 2021-01-16 23:44:43 +01:00
parent e6f10929b7
commit 285940c60a
3 changed files with 12 additions and 2 deletions

View File

@ -4,6 +4,7 @@ This project follows [semantic versioning](http://semver.org).
### UNRELEASED
- [added] Support for creating shell completions
- [removed] Removed dummy device type
- [changed] Updated depdendencies
- [changed] Changed Rust version to 1.49.0

View File

@ -10,6 +10,7 @@ use std::{
net::{IpAddr, Ipv6Addr, SocketAddr}
};
use structopt::StructOpt;
use structopt::clap::Shell;
pub const DEFAULT_PEER_TIMEOUT: u16 = 300;
@ -325,7 +326,7 @@ pub struct Args {
pub mode: Option<Mode>,
/// The shared password to encrypt all traffic
#[structopt(short, long, required_unless_one = &["private-key", "config", "genkey", "version"], env)]
#[structopt(short, long, required_unless_one = &["private-key", "config", "genkey", "version", "completion"], env)]
pub password: Option<String>,
/// The private key to use
@ -458,7 +459,11 @@ pub struct Args {
/// Migrate an old config file
#[structopt(long, alias = "migrate", requires = "config")]
pub migrate_config: bool
pub migrate_config: bool,
/// Generate shell completions
#[structopt(long)]
pub completion: Option<Shell>
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]

View File

@ -234,6 +234,10 @@ fn main() {
);
return
}
if let Some(shell) = args.completion {
Args::clap().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut io::stdout());
return
}
let logger = try_fail!(DualLogger::new(args.log_file.as_ref()), "Failed to open logfile: {}");
log::set_boxed_logger(Box::new(logger)).unwrap();
assert!(!args.verbose || !args.quiet);