Skip to content

Commit

Permalink
Implement autocompletion generation
Browse files Browse the repository at this point in the history
  • Loading branch information
eupn committed Sep 20, 2019
1 parent 6964dea commit 4eed2f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/completions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::{io, str::FromStr};

use crate::BoxResult;
use structopt::clap::{App, Shell};

/// Generates and outputs shell completion script for `rmob` for specific shell: bash, zsh, etc.
pub(crate) fn generate(app: &mut App, shell: &str) -> BoxResult<()> {
let shell = Shell::from_str(shell)?;
app.gen_completions_to("rmob", shell, &mut io::stdout());
Ok(())
}
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use git2::Repository;
use structopt::StructOpt;

mod active_copirate;
mod completions;
mod copirate;
mod embark;
mod prepare_commit_msg;
Expand Down Expand Up @@ -64,6 +65,9 @@ enum Command {
#[structopt(subcommand)]
cmd: CopirateSubcommand,
},
/// Generates autocompletion config for shell
#[structopt(name = "generate-shell-completions")]
GenerateShellCompletions { shell: String },
/// Called from the git hook only
#[structopt(name = "prepare-commit-msg")]
PrepareCommitMessage {
Expand Down Expand Up @@ -97,6 +101,9 @@ pub fn run() -> BoxResult<()> {
}
};
}
Command::GenerateShellCompletions { ref shell } => {
completions::generate(&mut Rmob::clap(), shell)?
}

Command::PrepareCommitMessage {
commit_message_file,
Expand Down

0 comments on commit 4eed2f6

Please sign in to comment.