Skip to content

Commit

Permalink
src: simplify generate_completions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelohdez committed Jun 13, 2024
1 parent f1338c2 commit 34558f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() -> anyhow::Result<()> {
let args = DimOpts::parse();

if let Some(path) = args.gen_completions {
DimOpts::generate_completions(Some(&path))?;
DimOpts::generate_completions(&path)?;
return Ok(());
}

Expand Down
18 changes: 4 additions & 14 deletions src/opts.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use std::{
borrow::Cow,
env,
ops::Deref,
path::{Path, PathBuf},
};
use std::path::{Path, PathBuf};

use clap::{CommandFactory, Parser, ValueEnum};
use clap_complete::{generate_to, Shell};
Expand Down Expand Up @@ -35,17 +30,12 @@ pub struct DimOpts {
}

impl DimOpts {
pub fn generate_completions(at: Option<&Path>) -> anyhow::Result<()> {
pub fn generate_completions(dir: &Path) -> anyhow::Result<()> {
let mut cli = Self::command();

let dir = match at {
Some(dir) => Cow::Borrowed(dir),
None => Cow::Owned(env::current_dir()?),
};

for &shell in Shell::value_variants() {
let comp_file = generate_to(shell, &mut cli, "dim", dir.deref())?;
println!("cargo:warning=generated completion for {shell}: {comp_file:?}");
let comp_file = generate_to(shell, &mut cli, "dim", dir)?;
println!("Generated completion for {shell} at {comp_file:?}");
}

Ok(())
Expand Down

0 comments on commit 34558f6

Please sign in to comment.