summaryrefslogtreecommitdiffstats
path: root/src
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 /src
parent0b97ac7602b93ea7a27e7a2bfa6e83f33b6fc9a8 (diff)
move gen_completions to an action
Diffstat (limited to 'src')
-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
4 files changed, 42 insertions, 1 deletions
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),