Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Schöchlin <[email protected]>
  • Loading branch information
scoopex committed Nov 30, 2024
1 parent 39fa6e9 commit c30df10
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,26 @@ use crate::utils::{dump_recipes, output_str, OutputType};
use std::env;
use std::io;

fn generate_completions<G: Generator>(shell: G) {
let mut cmd = CommandLineArgs::command();
let bin_name = env!("CARGO_PKG_NAME");
generate(shell, &mut cmd, bin_name, &mut io::stdout());

fn shell_completions(){
if let Some(shell) = env::args().nth(1) {
if shell == "generate-completions" {
if let Some(shell_name) = env::args().nth(2) {
let shell_enum = shell_name.parse::<Shell>();
if let Ok(shell_enum) = shell_enum {
let mut cmd = CommandLineArgs::command();
let bin_name = env!("CARGO_PKG_NAME");
generate(shell_enum, &mut cmd, bin_name, &mut io::stdout());
exit(0);
}
}
eprintln!("Usage: {} generate-completions <shell>", env!("CARGO_PKG_NAME"));
exit(1);
}
}
}


fn main() {
unsafe { libc::umask(0o077) };

Expand All @@ -31,19 +45,7 @@ fn main() {

let mut cli = CommandLineArgs::parse();

if let Some(shell) = env::args().nth(1) {
if shell == "generate-completions" {
if let Some(shell_name) = env::args().nth(2) {
let shell_enum = shell_name.parse::<Shell>();
if let Ok(shell_enum) = shell_enum {
generate_completions(shell_enum);
return;
}
}
eprintln!("Usage: {} generate-completions <shell>", env!("CARGO_PKG_NAME"));
return;
}
}
shell_completions();

env_logger::Builder::from_env(
Env::default().default_filter_or(cli.log_level.clone())
Expand Down

0 comments on commit c30df10

Please sign in to comment.