Skip to content

Commit

Permalink
Improve installation messages (#23)
Browse files Browse the repository at this point in the history
* Improve installatino prints

* Clippy, as well as changed forc toolchain -> fuel toolchain

* Suggest adding to path only if fully or partially installed

* Suggest adding to path only if fully/partially installed

* Remove suggest adding to path

* Move add to path messages to fuelup-init.sh

* Some more changes to messages

* refactor: use write! instead

* Fix curly braces
  • Loading branch information
bing authored Jun 6, 2022
1 parent 2687b57 commit 5f6ed4e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 17 deletions.
21 changes: 18 additions & 3 deletions fuelup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,27 @@ main() {
ignore rmdir "$_dir/fuelup-${_fuelup_version}-${_arch}"
ignore rmdir "$_dir"

printf '\n'
printf '%s\n' "fuelup ${_fuelup_version} has been installed in $FUELUP_DIR/bin. To fetch the latest forc and fuel-core binaries, run 'fuelup install'." 1>&2

post_setup_message
return "$_retval"
}

post_setup_message() {
cat 1>&2 <<EOF
fuelup v${_fuelup_version} has been installed in $FUELUP_DIR/bin. You might have to add $FUELUP_DIR/bin to path:
bash/zsh:
export PATH="\${HOME}/.fuelup/bin:\${PATH}"
fish:
fish_add_path ~/.fuelup/bin
To fetch the latest forc and fuel-core binaries, run 'fuelup install'.
EOF
}

get_architecture() {
local _ostype _cputype
_ostype="$(uname -s)"
Expand Down
70 changes: 56 additions & 14 deletions src/commands/install.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::fmt::Write;
use std::fs;

use anyhow::{bail, Result};
use clap::Parser;
use tracing::info;
use tracing::{error, info};

use crate::constants::{FUEL_CORE_RELEASE_DOWNLOAD_URL, SWAY_RELEASE_DOWNLOAD_URL};
use crate::download::{download_file_and_unpack, fuelup_bin_dir, unpack_extracted_bins};
Expand Down Expand Up @@ -42,30 +43,71 @@ pub fn install() -> Result<()> {
let fuel_core_bin_tarball_name = fuel_core_bin_tarball_name(&fuel_core_release_latest_tag)?;

info!("Fetching forc {}", &forc_release_latest_tag);
download_file_and_unpack(

let mut installed_bins_message = String::new();
let mut errored_bins_message = String::new();

match download_file_and_unpack(
SWAY_RELEASE_DOWNLOAD_URL,
&forc_release_latest_tag,
&forc_bin_tarball_name,
)?;
) {
Ok(()) => write!(
&mut installed_bins_message,
"forc {}",
&forc_release_latest_tag
)?,
Err(_) => write!(
&mut errored_bins_message,
"forc {}",
&forc_release_latest_tag
)?,
};

info!("Fetching fuel-core {}", &fuel_core_release_latest_tag);
download_file_and_unpack(
match download_file_and_unpack(
FUEL_CORE_RELEASE_DOWNLOAD_URL,
&fuel_core_release_latest_tag,
&fuel_core_bin_tarball_name,
)?;
) {
Ok(()) => {
if !installed_bins_message.is_empty() {
write!(&mut installed_bins_message, ", ")?
};
write!(
&mut installed_bins_message,
"fuel-core {}",
&fuel_core_release_latest_tag
)?;
}
Err(_) => {
if !errored_bins_message.is_empty() {
write!(&mut errored_bins_message, ", ")?
}
write!(
&mut errored_bins_message,
"fuel-core {}",
&fuel_core_release_latest_tag
)?;
}
};

unpack_extracted_bins(&fuelup_bin_dir)?;

info!(
"\n\nInstalled: forc {}, fuel-core {}",
forc_release_latest_tag, fuel_core_release_latest_tag
);
info!("\nThe Fuel toolchain is installed now. Great!");
info!(
"\nYou might need to add {} to your path.",
fuelup_bin_dir.display()
);
if errored_bins_message.is_empty() {
info!("\nInstalled: {}", installed_bins_message);
info!("\nThe Fuel toolchain is installed and up to date");
} else if installed_bins_message.is_empty() {
error!(
"\nfuelup failed to install: {}\n\nYou might need to run `fuelup install` again.",
errored_bins_message
)
} else {
info!(
"\nThe Fuel toolchain is partially installed.\nfuelup failed to install: {}\n\nYou might need to run `fuelup install` again.",
errored_bins_message
);
};

Ok(())
}

0 comments on commit 5f6ed4e

Please sign in to comment.