Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tool formatting: tool@version. #377

Merged
merged 1 commit into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/notion-core/src/distro/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::fs::ensure_containing_dir_exists;
use crate::hook::ToolHooks;
use crate::inventory::NodeCollection;
use crate::path;
use crate::style::progress_bar;
use crate::style::{progress_bar, tool_version};
use crate::tool::ToolSpec;
use crate::version::VersionSpec;

Expand Down Expand Up @@ -188,7 +188,7 @@ impl Distro for NodeDistro {
let temp = tempdir_in(path::tmp_dir()?).unknown()?;
let bar = progress_bar(
self.archive.origin(),
&format!("v{}", self.version),
&tool_version("node", &self.version),
self.archive
.uncompressed_size()
.unwrap_or(self.archive.compressed_size()),
Expand Down
4 changes: 2 additions & 2 deletions crates/notion-core/src/distro/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::path;
use crate::platform::{Image, PlatformSpec};
use crate::session::Session;
use crate::shim;
use crate::style::progress_bar;
use crate::style::{progress_bar, tool_version};
use crate::tool::ToolSpec;
use crate::version::VersionSpec;
use archive::{Archive, Tarball};
Expand Down Expand Up @@ -148,7 +148,7 @@ impl Distro for PackageDistro {

let bar = progress_bar(
archive.origin(),
&format!("{}-v{}", self.name, self.version),
&tool_version(&self.name, &self.version),
archive
.uncompressed_size()
.unwrap_or(archive.compressed_size()),
Expand Down
4 changes: 2 additions & 2 deletions crates/notion-core/src/distro/yarn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::fs::ensure_containing_dir_exists;
use crate::hook::ToolHooks;
use crate::inventory::YarnCollection;
use crate::path;
use crate::style::progress_bar;
use crate::style::{progress_bar, tool_version};
use crate::tool::ToolSpec;
use crate::version::VersionSpec;

Expand Down Expand Up @@ -135,7 +135,7 @@ impl Distro for YarnDistro {
let temp = tempdir_in(path::tmp_dir()?).unknown()?;
let bar = progress_bar(
self.archive.origin(),
&format!("v{}", self.version),
&tool_version("yarn", &self.version),
self.archive
.uncompressed_size()
.unwrap_or(self.archive.compressed_size()),
Expand Down
4 changes: 1 addition & 3 deletions crates/notion-core/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ impl Session {
let fetched_package = self.fetch_package(name, version)?;
let package_version = fetched_package.version();

let use_platform;

// This uses the "engines" field from package.json to determine the node version to use
// From https://docs.npmjs.com/files/package.json#engines:
//
Expand All @@ -221,7 +219,7 @@ impl Session {
let req_node_version = package_version.engines_spec()?;
let node_version = self.fetch_node(&req_node_version)?.into_version();

use_platform = Rc::new(PlatformSpec {
let use_platform = Rc::new(PlatformSpec {
node_runtime: node_version.runtime,
npm: Some(node_version.npm),
yarn: None,
Expand Down
8 changes: 8 additions & 0 deletions crates/notion-core/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ fn action_str(origin: Origin) -> &'static str {
}
}

pub fn tool_version<N, V>(name: N, version: V) -> String
where
N: std::fmt::Display + Sized,
V: std::fmt::Display + Sized,
{
format!("{:}@{:}", name, version)
}

/// Constructs a command-line progress bar based on the specified Origin enum
/// (e.g., `Origin::Remote`), details string (e.g., `"v1.23.4"`), and logical
/// length (i.e., the number of logical progress steps in the process being
Expand Down