forked from nivekuil/rip
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct output of shell completions
- Loading branch information
1 parent
5c49b52
commit 67ee0df
Showing
3 changed files
with
23 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
use clap::CommandFactory; | ||
use clap_complete::{generate, Shell}; | ||
use clap_complete_nushell::Nushell; | ||
use std::io::{self, Write}; | ||
use std::io::{Error, ErrorKind, Result, Write}; | ||
use std::str::FromStr; | ||
|
||
use crate::args; | ||
|
||
pub fn generate_shell_completions(shell_s: &str, buf: &mut dyn Write) { | ||
pub fn generate_shell_completions(shell_s: &str, buf: &mut dyn Write) -> Result<()> { | ||
if "nu" == shell_s || "nushell" == shell_s { | ||
let shell = Nushell; | ||
generate(shell, &mut args::Args::command(), "rip", buf); | ||
} else { | ||
let shell = Shell::from_str(shell_s).unwrap_or_else(|_| { | ||
eprintln!( | ||
"Invalid shell specification: {}. Available shells: bash, elvish, fish, powershell, zsh, nushell", | ||
shell_s | ||
); | ||
std::process::exit(1); | ||
}); | ||
generate(shell, &mut args::Args::command(), "rip", buf); | ||
let tryshell = Shell::from_str(shell_s); | ||
if tryshell.is_err() { | ||
return Err(Error::new( | ||
ErrorKind::InvalidInput, | ||
format!( | ||
"Invalid shell specification: {}. Available shells: bash, elvish, fish, powershell, zsh, nushell", | ||
shell_s | ||
) | ||
)); | ||
} | ||
generate(tryshell.unwrap(), &mut args::Args::command(), "rip", buf); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters