diff options
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | build.rs | 23 | ||||
-rw-r--r-- | src/actions/gen_completions.rs | 35 | ||||
-rw-r--r-- | src/actions/mod.rs | 1 | ||||
-rw-r--r-- | src/bin/khaleesi.rs | 1 | ||||
-rw-r--r-- | src/cli.rs | 6 |
6 files changed, 42 insertions, 29 deletions
@@ -3,7 +3,6 @@ name = "khaleesi" version = "0.1.0" authors = ["Nora <nora.widdecke@tu-bs.de>"] edition = "2018" -build = "build.rs" [dependencies] libc = "0.2.43" @@ -33,7 +32,3 @@ assert_fs = "0.11.3" predicates = "1.0" maplit = "1.0.1" pretty_assertions = "0.6.1" - -[build-dependencies] -clap = "2.32.0" -structopt = "0.2.14" diff --git a/build.rs b/build.rs deleted file mode 100644 index 7ac375c..0000000 --- a/build.rs +++ /dev/null @@ -1,23 +0,0 @@ -#[macro_use] -extern crate clap; -extern crate structopt; - -use std::env; -use structopt::clap::Shell; - -include!("src/cli.rs"); - -fn main() { - if env::var_os("PROFILE") == Some("release".into()) { - let outdir = match env::var_os("OUT_DIR") { - None => return, - Some(outdir) => outdir, - }; - let mut app = CommandLine::clap(); - let binary_name = "khaleesi"; - app.gen_completions(binary_name, Shell::Bash, &outdir); - app.gen_completions(binary_name, Shell::Zsh, &outdir); - app.gen_completions(binary_name, Shell::Fish, &outdir); - app.gen_completions(binary_name, Shell::Elvish, &outdir); - } -} diff --git a/src/actions/gen_completions.rs b/src/actions/gen_completions.rs new file mode 100644 index 0000000..b4c1946 --- /dev/null +++ b/src/actions/gen_completions.rs @@ -0,0 +1,35 @@ +use std::io; +use structopt::clap::Shell; +use structopt::StructOpt; + +use crate::cli::CommandLine; +use crate::KhResult; + +#[derive(Debug, StructOpt)] +pub struct GenCompletionsArgs { + /// the shell + #[structopt(name = "shell", raw(possible_values = "&ShellArg::variants()"))] + pub shell: ShellArg, +} + +arg_enum! { +#[derive(Debug)] + pub enum ShellArg{ + bash, + zsh, + fish, + elvish + } +} + +pub fn gen_completions(args: &GenCompletionsArgs) -> KhResult<()> { + let mut app = CommandLine::clap(); + let binary_name = "khaleesi"; + match args.shell { + ShellArg::bash => app.gen_completions_to(binary_name, Shell::Bash, &mut io::stdout()), + ShellArg::zsh => app.gen_completions_to(binary_name, Shell::Zsh, &mut io::stdout()), + ShellArg::fish => app.gen_completions_to(binary_name, Shell::Fish, &mut io::stdout()), + ShellArg::elvish => app.gen_completions_to(binary_name, Shell::Elvish, &mut io::stdout()), + } + Ok(()) +} diff --git a/src/actions/mod.rs b/src/actions/mod.rs index 594b7e8..ad58bb6 100644 --- a/src/actions/mod.rs +++ b/src/actions/mod.rs @@ -14,3 +14,4 @@ pub mod seq; pub mod show; pub mod undo; pub mod unroll; +pub mod gen_completions; diff --git a/src/bin/khaleesi.rs b/src/bin/khaleesi.rs index 5328af2..b1764ac 100644 --- a/src/bin/khaleesi.rs +++ b/src/bin/khaleesi.rs @@ -44,6 +44,7 @@ fn main_internal(args: &cli::CommandLine, config: &Config) -> KhResult<()> { cli::Command::Delete => delete::do_delete(), cli::Command::Edit => edit::do_edit(), cli::Command::Get(x) => get::action_get(x), + cli::Command::GenCompletions(x) => gen_completions::gen_completions(x), cli::Command::Index(x) => index::action_index(x), cli::Command::List(x) => { list::list_by_args(&x.args.iter().map(|x| x.as_ref()).collect::<Vec<&str>>()) @@ -1,6 +1,8 @@ use std::path::PathBuf; use structopt::StructOpt; +use crate::actions::gen_completions::GenCompletionsArgs; + #[derive(Debug, StructOpt)] #[structopt( author = "", @@ -8,7 +10,6 @@ use structopt::StructOpt; about = "Command line calendar tool.", raw(setting = "structopt::clap::AppSettings::VersionlessSubcommands") )] - pub struct CommandLine { /// verbosity #[structopt(short = "v", parse(from_occurrences))] @@ -37,6 +38,9 @@ pub enum Command { /// Get info about the calendar data #[structopt(name = "get", author = "")] Get(GetArgs), + /// Print shell completions script to stdout + #[structopt(name = "gen-completions", author = "")] + GenCompletions(GenCompletionsArgs), /// Rebuild index #[structopt(name = "index", author = "")] Index(IndexArgs), |