Skip to content

Commit

Permalink
add completion support
Browse files Browse the repository at this point in the history
  • Loading branch information
glehmann committed Feb 2, 2024
1 parent 696b966 commit 9edd8c1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ base64 = "0.21.7"
clap = { version = "4.4.18", features = ["derive", "env", "wrap_help"] }
clap-markdown = "0.1.3"
clap-verbosity-flag = "2.1.2"
clap_complete = "4.4.10"
log = "0.4.20"
ocli = "0.1.1"
serde_yaml = "0.9.31"
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use clap_verbosity_flag::{InfoLevel, Verbosity};
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None, arg_required_else_help = true)]
pub struct Cli {
/// Generate the completion code for this shell
#[arg(long, name = "SHELL")]
pub completion: Option<clap_complete::Shell>,

#[command(flatten)]
pub verbose: Verbosity<InfoLevel>,

Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#[macro_use]
extern crate log;

use std::io;

use clap::CommandFactory;
use clap::Parser;

use yage::cli;
Expand All @@ -18,6 +21,11 @@ fn run() -> error::Result<()> {
ocli::init(level).unwrap();
}

if let Some(shell) = cli.completion {
clap_complete::generate(shell, &mut cli::Cli::command(), "yage", &mut io::stdout());
return Ok(());
}

if cli.markdown_help {
clap_markdown::print_help_markdown::<cli::Cli>();
return Ok(());
Expand Down

0 comments on commit 9edd8c1

Please sign in to comment.