Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
crodas committed Feb 15, 2024
1 parent 966e641 commit 6572be0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion forc/src/cli/commands/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ pub(crate) fn exec(command: Command) -> ForcResult<()> {
}
});

// Where to store the autocomplete script, ZSH requires a special path, the other shells are
// stored in the same path and they are referenced form their respective config files
let dir = home::home_dir().map(|p| p.display().to_string()).unwrap();
let forc_autocomplete_path = match target {
Target::Zsh => {
Expand All @@ -134,9 +136,13 @@ pub(crate) fn exec(command: Command) -> ForcResult<()> {
_ => format!("{}/.forc.autocomplete", dir),
};

let mut file = File::create(&forc_autocomplete_path).expect("Open the shell config file");
let mut file = File::create(&forc_autocomplete_path).unwrap_or_else(|_| {
panic!("Cannot write to the autocomplete file in path {forc_autocomplete_path}")
});
generate_autocomplete_script(target, &mut file);

// Check if the shell config file already has the forc completions. Some shells do not require
// this step, therefore this maybe None
let user_shell_config = match target {
Target::Fish => Some(format!("{}/.config/fish/config.fish", dir)),
Target::Elvish => Some(format!("{}/.elvish/rc.elv", dir)),
Expand All @@ -150,6 +156,7 @@ pub(crate) fn exec(command: Command) -> ForcResult<()> {
};

if let Some(file_path) = user_shell_config {
// Update the user_shell_config
let file = File::open(&file_path).expect("Open the shell config file");
let reader = BufReader::new(file);

Expand Down

0 comments on commit 6572be0

Please sign in to comment.