Skip to content

Commit

Permalink
Improve information messages
Browse files Browse the repository at this point in the history
  • Loading branch information
chshersh committed Sep 12, 2022
1 parent f11f7b5 commit d2c31ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ For more details, refer to the official documentation:
}

const DONE: Emoji<'_, '_> = Emoji("✨ ", "* ");
const DIRECTORY: Emoji<'_, '_> = Emoji("📁 ", "* ");

fn sync_tools(config: Config) {
let store_directory = config.ensure_store_directory();
Expand All @@ -58,7 +59,7 @@ fn sync_tools(config: Config) {
.collect();

let sync_progress = SyncProgress::new(tool_pairs);
let installer = Installer::mk(store_directory, sync_progress);
let installer = Installer::mk(store_directory.as_path(), sync_progress);

let mut installed_tools: u64 = 0;

Expand All @@ -70,4 +71,9 @@ fn sync_tools(config: Config) {
}

eprintln!("{} Successfully installed {} tools!", DONE, installed_tools);
eprintln!(
"{} Installation directory: {}",
DIRECTORY,
store_directory.display()
);
}
14 changes: 7 additions & 7 deletions src/sync/install.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use indicatif::ProgressBar;
use std::error::Error;
use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use tempdir::TempDir;

#[cfg(target_family = "unix")]
Expand All @@ -15,16 +15,16 @@ use super::archive::Archive;
use super::download::Downloader;
use super::progress::SyncProgress;

pub struct Installer {
store_directory: PathBuf,
pub struct Installer<'a> {
store_directory: &'a Path,
tmp_dir: TempDir,
sync_progress: SyncProgress,
}

impl Installer {
impl<'a> Installer<'a> {
/// This functions panics when it can't create a temporary directory
/// (e.g. not enough disk space?)
pub fn mk(store_directory: PathBuf, sync_progress: SyncProgress) -> Installer {
pub fn mk(store_directory: &Path, sync_progress: SyncProgress) -> Installer {
let tmp_dir = TempDir::new("tool-sync");
match tmp_dir {
Err(e) => {
Expand Down Expand Up @@ -84,15 +84,15 @@ impl Installer {
Some(archive) => match archive.unpack() {
Err(unpack_err) => Err(unpack_err.display().into()),
Ok(tool_path) => {
copy_file(tool_path, &self.store_directory, &tool_asset.exe_name)?;
copy_file(tool_path, self.store_directory, &tool_asset.exe_name)?;
Ok(())
}
},
}
}
}

fn copy_file(tool_path: PathBuf, store_directory: &PathBuf, exe_name: &str) -> std::io::Result<()> {
fn copy_file(tool_path: PathBuf, store_directory: &Path, exe_name: &str) -> std::io::Result<()> {
let exe_name = mk_exe_name(exe_name);

let mut install_path = PathBuf::new();
Expand Down
2 changes: 1 addition & 1 deletion src/sync/prefetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn prefetch(tools: BTreeMap<String, ConfigAsset>) -> Vec<ToolAsset> {
let estimated_download_size: u64 = tool_assets.iter().map(|ta| ta.asset.size).sum();
let size = HumanBytes(estimated_download_size);
eprintln!(
"{emoji} Estimated download size: {size}",
"{emoji} Estimated total download size: {size}",
emoji = PACKAGE,
size = size
);
Expand Down

0 comments on commit d2c31ed

Please sign in to comment.