Skip to content

Commit

Permalink
Improving errors
Browse files Browse the repository at this point in the history
  • Loading branch information
freexploit committed Apr 28, 2024
1 parent 9d4c09c commit 3c66da7
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions crates/aiken/src/cmd/completion/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn generate_wrapper(shell: Shell, buf: &mut dyn Write) {
fn zsh() -> miette::Result<()> {
//if oh-my-zsh
let home = std::env::var("HOME").expect("Cannot find your home directory");
let xdg_dirs = xdg::BaseDirectories::with_prefix("zsh-completions/site-functions").unwrap();
let xdg_dirs = xdg::BaseDirectories::with_prefix("zsh-completions/site-functions").expect("Cannot load xdg-base directory");
let data_home = xdg_dirs.get_data_home();
let mut completion_file: File;

Expand All @@ -32,9 +32,9 @@ fn zsh() -> miette::Result<()> {
let completions_path = oh_my_zsh_path.join("completions");
let aiken_completion_path = completions_path.join("_aiken");
if !completions_path.exists() {
std::fs::create_dir(completions_path.as_path()).expect("cannot create directory");
std::fs::create_dir(completions_path.as_path()).expect("Cannot create directory: {completions_path.into_os_string().into_string()}");
}
completion_file = File::create(aiken_completion_path).expect("cannot open file");
completion_file = File::create(aiken_completion_path).expect("Cannot open file at: {aiken_completion_path.into_os_string().into_string()}");

generate_wrapper(Shell::Zsh, &mut completion_file);
return Ok(());
Expand All @@ -45,15 +45,15 @@ fn zsh() -> miette::Result<()> {
let completion_path = xdg_dirs
.place_data_file("_aiken")
.expect("cannot create directory");
completion_file = File::create(completion_path).expect("cannot open file");
completion_file = File::create(completion_path).expect("Cannot open file at: {completion_path.into_os_string().into_string()}");
generate_wrapper(Shell::Zsh, &mut completion_file);
return Ok(());
}

let completion_path = xdg_dirs
.place_data_file("_aiken")
.expect("cannot create directory");
completion_file = File::create(completion_path).expect("cannot open file");
completion_file = File::create(completion_path).expect("Cannot open file at: {completion_path.into_os_string().into_string()}");

let mut zshrc = OpenOptions::new()
.write(true)
Expand All @@ -74,20 +74,20 @@ fn zsh() -> miette::Result<()> {

fn fish() -> miette::Result<()> {
// NOTE: Installing completion on ~/.confi/fish/completions
let xdg_dirs = xdg::BaseDirectories::with_prefix("fish/completions").expect("Error finding directory");
let xdg_dirs = xdg::BaseDirectories::with_prefix("fish/completions").expect("Cannot find xdg-base directory");
let completion_path = xdg_dirs
.place_config_file("aiken.fish").expect("Cannot create path");
let mut completion_file = File::create(completion_path).expect("cannot open file");
let mut completion_file = File::create(completion_path).expect("Cannot open file at: {completion_path.into_os_string().into_string()}");
generate_wrapper(Shell::Fish, &mut completion_file);
Ok(())
}

fn bash() -> miette::Result<()> {
let xdg_dirs = xdg::BaseDirectories::with_prefix("bash-completion/completions").expect("Error finding directory");
let xdg_dirs = xdg::BaseDirectories::with_prefix("bash-completion/completions").expect("Cannot find xdg-base directory");
let home = std::env::var("HOME").expect("Cannot find your home directory");
let config_home = xdg_dirs.get_config_home();
let completion_path = xdg_dirs
.place_config_file("aiken.completion.bash").expect("Cannot create path");
.place_config_file("aiken.completion.bash").expect("Cannot create file at: ~/config/bash-completion/completions");

let mut bashrc = OpenOptions::new()
.write(true)
Expand All @@ -100,7 +100,7 @@ fn bash() -> miette::Result<()> {
eprintln!("Couldn't write to file: {}", e);
}
}
let mut completion_file = File::create(completion_path).expect("cannot open file");
let mut completion_file = File::create(completion_path).expect("Cannot open file at: {completion_path.into_os_string().into_string()}");
generate_wrapper(Shell::Bash, &mut completion_file);
Ok(())
}
Expand Down

0 comments on commit 3c66da7

Please sign in to comment.