Skip to content

Commit

Permalink
fix completion generators if usage is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 11, 2024
1 parent 111a218 commit e46fe04
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/cli/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ impl Completion {
let shell = self.shell.or(self.shell_type).unwrap();

if self.usage || matches!(shell, Shell::Bash | Shell::Fish) {
let shell = shell.to_string();
cmd!(
let res = cmd!(
"usage",
"generate",
"completion",
&shell,
shell.to_string(),
"mise",
"--usage-cmd",
"mise usage"
)
.run()?;
.run();
if res.is_err() {
return self.prerendered(shell);
}
return Ok(());
}

Expand All @@ -56,6 +58,16 @@ impl Completion {

Ok(())
}

fn prerendered(&self, shell: Shell) -> Result<()> {
let script = match shell {
Shell::Bash => include_str!("../../completions/mise.bash"),
Shell::Fish => include_str!("../../completions/mise.fish"),
Shell::Zsh => include_str!("../../completions/_mise"),
};
miseprintln!("{}", script.trim())?;
Ok(())
}
}

static AFTER_LONG_HELP: &str = color_print::cstr!(
Expand All @@ -67,7 +79,7 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
"#
);

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy)]
enum Shell {
Bash,
Fish,
Expand Down

0 comments on commit e46fe04

Please sign in to comment.