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

new: Improve partial/full version handling. #190

Merged
merged 6 commits into from
Sep 7, 2023
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
#### 🚀 Updates

- Added colors to command line `--help` menus.
- Updated the following locations to support partial versions and aliases:
- Tool versions in `.prototools`.
- Pinning a default version with `proto install --pin`.
- Setting global version with `proto global`.
- Setting local version with `proto local`.
- WASM API
- Added `is_musl` and `get_target_triple` helper functions.
- Added `command_exists`, `is_musl`, and `get_target_triple` helper functions.

#### ⚙️ Internal

- Now supports `.zst` (or `.zstd`) archive formats.
- Improved version, alias, and requirement handling.

## 0.16.1

Expand Down
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ semver = "1.0.18"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.105"
sha2 = "0.10.7"
starbase_archive = { version = "0.2.1", features = [
starbase_archive = { version = "0.2.2", features = [
"tar-gz",
"tar-xz",
"tar-zstd",
"zip",
"zip-deflate",
] }
starbase_sandbox = { version = "0.1.9" }
starbase_styles = "0.1.14"
starbase_utils = { version = "0.2.22", default-features = false, features = [
starbase_sandbox = { version = "0.1.10" }
starbase_styles = "0.1.15"
starbase_utils = { version = "0.3.1", default-features = false, features = [
"json",
"toml",
] }
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/commands/alias.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Args;
use proto_core::{is_alias_name, load_tool, Id, ProtoError, VersionType};
use proto_core::{is_alias_name, load_tool, Id, ProtoError, UnresolvedVersionSpec};
use starbase::system;
use starbase_styles::color;
use tracing::info;
Expand All @@ -13,12 +13,12 @@ pub struct AliasArgs {
alias: String,

#[arg(required = true, help = "Version or alias to associate with")]
semver: VersionType,
spec: UnresolvedVersionSpec,
}

#[system]
pub async fn alias(args: ArgsRef<AliasArgs>) {
if let VersionType::Alias(inner_alias) = &args.semver {
if let UnresolvedVersionSpec::Alias(inner_alias) = &args.spec {
if &args.alias == inner_alias {
return Err(ProtoError::Message("Cannot map an alias to itself.".into()))?;
}
Expand All @@ -34,13 +34,13 @@ pub async fn alias(args: ArgsRef<AliasArgs>) {

tool.manifest
.aliases
.insert(args.alias.clone(), args.semver.clone());
.insert(args.alias.clone(), args.spec.clone());
tool.manifest.save()?;

info!(
"Added alias {} ({}) for {}",
color::id(&args.alias),
color::muted_light(args.semver.to_string()),
color::muted_light(args.spec.to_string()),
tool.get_name(),
);
}
6 changes: 3 additions & 3 deletions crates/cli/src/commands/bin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Args;
use proto_core::{detect_version, load_tool, Id, VersionType};
use proto_core::{detect_version, load_tool, Id, UnresolvedVersionSpec};
use starbase::system;

#[derive(Args, Clone, Debug)]
Expand All @@ -8,7 +8,7 @@ pub struct BinArgs {
id: Id,

#[arg(help = "Version or alias of tool")]
semver: Option<VersionType>,
spec: Option<UnresolvedVersionSpec>,

#[arg(long, help = "Display shim path when available")]
shim: bool,
Expand All @@ -17,7 +17,7 @@ pub struct BinArgs {
#[system]
pub async fn bin(args: ArgsRef<BinArgs>) {
let mut tool = load_tool(&args.id).await?;
let version = detect_version(&tool, args.semver.clone()).await?;
let version = detect_version(&tool, args.spec.clone()).await?;

tool.resolve_version(&version).await?;
tool.locate_bins().await?;
Expand Down
9 changes: 4 additions & 5 deletions crates/cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use clap::Args;
use dialoguer::Confirm;
use proto_core::{
get_plugins_dir, get_shim_file_name, load_tool, AliasOrVersion, Id, Tool, ToolsConfig,
get_plugins_dir, get_shim_file_name, load_tool, Id, Tool, ToolsConfig, VersionSpec,
};
use proto_pdk_api::{CreateShimsInput, CreateShimsOutput};
use semver::Version;
use starbase::diagnostics::IntoDiagnostic;
use starbase::{system, SystemResult};
use starbase_styles::color;
Expand Down Expand Up @@ -53,7 +52,7 @@ pub async fn clean_tool(mut tool: Tool, now: u128, days: u8, yes: bool) -> miett
return Ok(0);
}

let mut versions_to_clean = HashSet::<Version>::new();
let mut versions_to_clean = HashSet::<VersionSpec>::new();

debug!("Scanning file system for stale and untracked versions");

Expand All @@ -71,7 +70,7 @@ pub async fn clean_tool(mut tool: Tool, now: u128, days: u8, yes: bool) -> miett
continue;
}

let version = Version::parse(&dir_name).into_diagnostic()?;
let version = VersionSpec::parse(&dir_name)?;

if !tool.manifest.versions.contains_key(&version) {
debug!(
Expand Down Expand Up @@ -141,7 +140,7 @@ pub async fn clean_tool(mut tool: Tool, now: u128, days: u8, yes: bool) -> miett
.into_diagnostic()?
{
for version in versions_to_clean {
tool.set_version(AliasOrVersion::Version(version));
tool.set_version(version);
tool.teardown().await?;
}

Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/commands/global.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Args;
use proto_core::{load_tool, AliasOrVersion, Id};
use proto_core::{load_tool, Id, UnresolvedVersionSpec};
use starbase::system;
use starbase_styles::color;
use tracing::{debug, info};
Expand All @@ -10,25 +10,25 @@ pub struct GlobalArgs {
id: Id,

#[arg(required = true, help = "Version or alias of tool")]
semver: AliasOrVersion,
spec: UnresolvedVersionSpec,
}

#[system]
pub async fn global(args: ArgsRef<GlobalArgs>) -> SystemResult {
let mut tool = load_tool(&args.id).await?;

tool.manifest.default_version = Some(args.semver.clone());
tool.manifest.default_version = Some(args.spec.clone());
tool.manifest.save()?;

debug!(
version = args.semver.to_string(),
version = args.spec.to_string(),
manifest = ?tool.manifest.path,
"Wrote the global version",
);

info!(
"Set the global {} version to {}",
tool.get_name(),
color::hash(args.semver.to_string())
color::hash(args.spec.to_string())
);
}
8 changes: 4 additions & 4 deletions crates/cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::helpers::{create_progress_bar, disable_progress_bars};
use crate::shell;
use clap::Args;
use miette::IntoDiagnostic;
use proto_core::{load_tool, Id, Tool, VersionType};
use proto_core::{load_tool, Id, Tool, UnresolvedVersionSpec};
use proto_pdk_api::{InstallHook, SyncShellProfileInput, SyncShellProfileOutput};
use starbase::{system, SystemResult};
use starbase_styles::color;
Expand All @@ -15,7 +15,7 @@ pub struct InstallArgs {
pub id: Id,

#[arg(default_value = "latest", help = "Version or alias of tool")]
pub semver: Option<VersionType>,
pub spec: Option<UnresolvedVersionSpec>,

#[arg(long, help = "Pin version as the global default")]
pub pin: bool,
Expand All @@ -26,7 +26,7 @@ pub struct InstallArgs {
}

pub async fn internal_install(args: InstallArgs) -> SystemResult {
let version = args.semver.clone().unwrap_or_default();
let version = args.spec.clone().unwrap_or_default();
let mut tool = load_tool(&args.id).await?;

if tool.is_setup(&version).await? {
Expand Down Expand Up @@ -76,7 +76,7 @@ pub async fn internal_install(args: InstallArgs) -> SystemResult {
tool.cleanup().await?;

if args.pin {
tool.manifest.default_version = Some(tool.get_resolved_version());
tool.manifest.default_version = Some(tool.get_resolved_version().to_unresolved_spec());
tool.manifest.save()?;
}

Expand Down
8 changes: 3 additions & 5 deletions crates/cli/src/commands/install_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use crate::{
helpers::create_progress_bar,
};
use futures::future::try_join_all;
use proto_core::{
load_tool_from_locator, AliasOrVersion, ProtoEnvironment, ToolsConfig, UserConfig,
};
use proto_core::{load_tool_from_locator, ProtoEnvironment, ToolsConfig, UserConfig};
use starbase::system;
use starbase_styles::color;
use std::env;
Expand Down Expand Up @@ -40,7 +38,7 @@ pub async fn install_all() {

debug!("Detected version {} for {}", version, tool.get_name());

config.tools.insert(name, AliasOrVersion::Version(version));
config.tools.insert(name, version.to_unresolved_spec());
}
}

Expand All @@ -65,9 +63,9 @@ pub async fn install_all() {
for (id, version) in config.tools {
futures.push(internal_install(InstallArgs {
id,
semver: Some(version.to_implicit_type()),
pin: false,
passthrough: vec![],
spec: Some(version),
}));
}

Expand Down
7 changes: 4 additions & 3 deletions crates/cli/src/commands/list_remote.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Args;
use proto_core::{load_tool, Id, VersionType};
use proto_core::{load_tool, Id, UnresolvedVersionSpec};
use starbase::system;
use std::process;
use tracing::debug;
Expand All @@ -10,14 +10,15 @@ pub struct ListRemoteArgs {
id: Id,
}

// TODO: only show LTS, dont show pre-releases?
#[system]
pub async fn list_remote(args: ArgsRef<ListRemoteArgs>) {
let tool = load_tool(&args.id).await?;

debug!("Loading versions");

let resolver = tool.load_version_resolver(&VersionType::default()).await?;
let resolver = tool
.load_version_resolver(&UnresolvedVersionSpec::default())
.await?;
let mut versions = resolver.versions;

if versions.is_empty() {
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/src/commands/local.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Args;
use proto_core::{load_tool, AliasOrVersion, Id, ToolsConfig};
use proto_core::{load_tool, Id, ToolsConfig, UnresolvedVersionSpec};
use starbase::system;
use starbase_styles::color;
use std::{env, path::PathBuf};
Expand All @@ -11,7 +11,7 @@ pub struct LocalArgs {
id: Id,

#[arg(required = true, help = "Version or alias of tool")]
semver: AliasOrVersion,
spec: UnresolvedVersionSpec,
}

#[system]
Expand All @@ -20,18 +20,18 @@ pub async fn local(args: ArgsRef<LocalArgs>) {
let local_path = env::current_dir().unwrap_or_else(|_| PathBuf::from("."));

let mut config = ToolsConfig::load_from(local_path)?;
config.tools.insert(args.id.clone(), args.semver.clone());
config.tools.insert(args.id.clone(), args.spec.clone());
config.save()?;

debug!(
version = args.semver.to_string(),
version = args.spec.to_string(),
config = ?config.path,
"Wrote the local version",
);

info!(
"Set the local {} version to {}",
tool.get_name(),
color::hash(args.semver.to_string())
color::hash(args.spec.to_string())
);
}
Loading