From c29ba3d67a9841ebe44eda1baeafc2cc6a3ca228 Mon Sep 17 00:00:00 2001 From: Vasili Novikov Date: Mon, 11 Mar 2019 23:56:27 +0100 Subject: [PATCH] add completions generation example (#169) --- examples/gen_completions.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 examples/gen_completions.rs diff --git a/examples/gen_completions.rs b/examples/gen_completions.rs new file mode 100644 index 00000000..26b30cb2 --- /dev/null +++ b/examples/gen_completions.rs @@ -0,0 +1,29 @@ +// Copyright 2019-present structopt developers +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[macro_use] +extern crate structopt; + +use structopt::clap::Shell; +use structopt::StructOpt; + +#[derive(StructOpt, Debug)] +#[structopt(name = "example", about = "An example of StructOpt usage.")] +struct Opt { + /// A flag, true if used in the command line. + #[structopt(short = "d", long = "debug", help = "Activate debug mode")] + debug: bool, +} + +fn main() { + // generate `bash` completions in "target" directory + Opt::clap().gen_completions(env!("CARGO_PKG_NAME"), Shell::Bash, "target"); + + let opt = Opt::from_args(); + println!("{:?}", opt); +}