summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora <nora.widdecke@tu-bs.de>2019-02-26 22:33:53 +0100
committerNora <nora.widdecke@tu-bs.de>2019-02-26 22:59:44 +0100
commit9e7cefd3dd5bff01ecbb063e3635a6a732593b64 (patch)
tree8d42822cacc16f329d58ec78a25de4632234e9b5
parent0b97ac7602b93ea7a27e7a2bfa6e83f33b6fc9a8 (diff)
move gen_completions to an action
-rw-r--r--Cargo.toml5
-rw-r--r--build.rs23
-rw-r--r--src/actions/gen_completions.rs35
-rw-r--r--src/actions/mod.rs1
-rw-r--r--src/bin/khaleesi.rs1
-rw-r--r--src/cli.rs6
6 files changed, 42 insertions, 29 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 0f8a511..1278063 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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>>())
diff --git a/src/cli.rs b/src/cli.rs
index a7843f4..ef14709 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -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),