Skip to content

Commit

Permalink
feat(binstall): adds postinstall instructions (#406)
Browse files Browse the repository at this point in the history
* feat(binstall): adds postinstall instructions

* Revert "feat(binstall): don't require terminal reload (#318)"

This reverts commit 7fb6f21.

* fix: clippy warning
  • Loading branch information
EverlastingBugstopper authored Mar 31, 2021
1 parent b585f11 commit f6c064f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 34 deletions.
2 changes: 1 addition & 1 deletion installers/binstall/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Installer {
Ok(base_dir.join(&format!(".{}", &self.binary_name)))
}

pub(crate) fn get_bin_dir_path(&self) -> Result<Utf8PathBuf, InstallerError> {
pub fn get_bin_dir_path(&self) -> Result<Utf8PathBuf, InstallerError> {
let bin_dir = self.get_base_dir_path()?.join("bin");
Ok(bin_dir)
}
Expand Down
24 changes: 0 additions & 24 deletions installers/binstall/src/system/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use camino::Utf8PathBuf;
use std::fmt::Debug;
use std::fs;
use std::io::{self, Write};
use std::process::Command;
use std::{env, path::PathBuf};

use crate::{Installer, InstallerError};
Expand All @@ -25,14 +24,6 @@ pub fn add_binary_to_path(installer: &Installer) -> Result<(), InstallerError> {
dest_file.sync_data()?;
}
}

// run the `source env` command so folks don't need to
// re-source their shell. the binary will be available for
// execution immediately after installation.
let _ = Command::new(shell.name())
.arg("-c")
.arg(&source_cmd)
.output();
}

Ok(())
Expand Down Expand Up @@ -89,9 +80,6 @@ trait UnixShell: Debug {
// Gives rcs that should be written to.
fn update_rcs(&self) -> Vec<Utf8PathBuf>;

// Gets the name of the shell.
fn name(&self) -> &str;

// Writes the relevant env file.
fn env_script(&self) -> ShellScript {
ShellScript {
Expand All @@ -112,10 +100,6 @@ trait UnixShell: Debug {
struct Posix;

impl UnixShell for Posix {
fn name(&self) -> &str {
"sh"
}

fn does_exist(&self) -> bool {
true
}
Expand All @@ -138,10 +122,6 @@ impl UnixShell for Posix {
struct Bash;

impl UnixShell for Bash {
fn name(&self) -> &str {
"bash"
}

fn does_exist(&self) -> bool {
!self.update_rcs().is_empty()
}
Expand Down Expand Up @@ -205,10 +185,6 @@ fn has_cmd(cmd: &str) -> bool {
}

impl UnixShell for Zsh {
fn name(&self) -> &str {
"zsh"
}

fn does_exist(&self) -> bool {
// zsh has to either be the shell or be callable for zsh setup.
matches!(env::var("SHELL"), Ok(sh) if sh.contains("zsh")) || matches!(has_cmd("zsh"), true)
Expand Down
34 changes: 25 additions & 9 deletions src/command/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,36 @@ impl Install {
if let Ok(executable_location) = env::current_exe() {
let executable_location = Utf8PathBuf::from_path_buf(executable_location)
.map_err(|pb| anyhow!("File path \"{}\" is not valid UTF-8", pb.display()))?;
let install_location = Installer {
let installer = Installer {
binary_name: binary_name.clone(),
force_install: self.force,
override_install_path,
executable_location,
}
.install()
.with_context(|| format!("could not install {}", &binary_name))?;
};
let install_location = installer
.install()
.with_context(|| format!("could not install {}", &binary_name))?;

if let Some(install_location) = install_location {
eprintln!(
"{} was successfully installed to `{}`.",
&binary_name, install_location
)
if install_location.is_some() {
let bin_dir_path = installer.get_bin_dir_path()?;
eprintln!("{} was successfully installed. Great!", &binary_name);
if !cfg!(windows) {
if let Some(path_var) = env::var_os("PATH") {
if !path_var
.to_string_lossy()
.to_string()
.contains(bin_dir_path.as_str())
{
eprintln!("\nTo get started you need Rover's bin directory ({}) in your PATH environment variable. Next time you log in this will be done automatically.", &bin_dir_path);
if let Ok(shell_var) = env::var("SHELL") {
eprintln!(
"\nTo configure your current shell, you can run:\nexec {}",
&shell_var
);
}
}
}
}
} else {
eprintln!("{} was not installed. To override the existing installation, you can pass the `--force` flag to the installer.", &binary_name);
}
Expand Down

0 comments on commit f6c064f

Please sign in to comment.