Skip to content

Commit

Permalink
✨ add arg to generate shell completions
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Dec 19, 2024
1 parent f9ce06e commit 76378bf
Show file tree
Hide file tree
Showing 4 changed files with 25 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 @@ -40,6 +40,7 @@ strum_macros = "0.26"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
scopeguard = "1.2"
unicode-width = "0.2"
clap_complete = "4.5.40"

[dev-dependencies]
strip-ansi-escapes = "0.2"
Expand Down
5 changes: 5 additions & 0 deletions src/modules/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{bail, Result};
use chrono::NaiveDate;
use clap::{Parser, ValueEnum};
use clap_complete::Shell;
use serde::{Deserialize, Serialize};
use strum_macros::AsRefStr;

Expand Down Expand Up @@ -34,6 +35,10 @@ pub struct Cli {
/// Wipe wthrr's configuration data
#[arg(short, long, group = "config_file_action")]
pub reset: bool,

/// Generate shell completions
#[arg(long, value_name = "SHELL")]
pub completions: Option<Shell>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, AsRefStr, Serialize, Deserialize, Hash)]
Expand Down
9 changes: 9 additions & 0 deletions src/modules/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::collections::HashSet;

use anyhow::{Context, Result};
use chrono::NaiveDate;
use clap::CommandFactory;
use clap_complete::generate;
use dialoguer::{theme::ColorfulTheme, Confirm, Select};

use super::{
Expand All @@ -21,6 +23,13 @@ pub struct Params {

impl Params {
pub async fn merge(config: &Config, args: &Cli) -> Result<Self> {
if let Some(shell) = args.completions {
let mut cmd = Cli::command();
let bin_name = cmd.get_name().to_string();
generate(shell, &mut cmd, bin_name, &mut std::io::stdout());
std::process::exit(0);
}

let language = match &args.language {
Some(lang) => lang.to_string(),
None => config.language.clone(),
Expand Down

0 comments on commit 76378bf

Please sign in to comment.