Skip to content
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
6 changes: 3 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "suiup"
description = "Sui Tooling Version Manager."
version = "0.0.5"
edition = "2021"
version = "0.0.6"
edition = "2024"

[dependencies]
anyhow = "1.0.98"
Expand Down
16 changes: 10 additions & 6 deletions src/commands/default/set.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::{anyhow, bail, Result};
use anyhow::{Result, anyhow, bail};
use clap::Args;
use tracing::{debug, info};

use crate::{
commands::{parse_component_with_version, BinaryName, CommandMetadata},
commands::{BinaryName, CommandMetadata, parse_component_with_version},
handlers::{installed_binaries_grouped_by_network, update_default_version_file},
paths::{binaries_dir, get_default_bin_dir},
};
Expand Down Expand Up @@ -42,7 +42,9 @@ impl Command {
} = self;

if name.is_empty() && nightly.is_none() {
bail!("Invalid number of arguments. Version is required: '[email protected]', 'sui@testnet' -- this will use an installed binary that has the highest testnet version. \n For `mvr` only pass the version: `[email protected]`")
bail!(
"Invalid number of arguments. Version is required: '[email protected]', 'sui@testnet' -- this will use an installed binary that has the highest testnet version. \n For `mvr` only pass the version: `[email protected]`"
)
}

let CommandMetadata {
Expand All @@ -52,12 +54,12 @@ impl Command {
} = parse_component_with_version(name)?;

let network = if name == BinaryName::Mvr {
if let Some(ref nightly) = nightly {
if let Some(nightly) = nightly {
nightly
} else {
"standalone"
}
} else if let Some(ref nightly) = nightly {
} else if let Some(nightly) = nightly {
nightly
} else {
&network
Expand All @@ -74,7 +76,9 @@ impl Command {
.values()
.any(|bins| bins.iter().any(|x| x.binary_name == name.to_string()));
if !binary_exists {
bail!("Binary {name} not found in installed binaries. Use `suiup show` to see installed binaries.");
bail!(
"Binary {name} not found in installed binaries. Use `suiup show` to see installed binaries."
);
}

let version = if let Some(version) = version {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod which;

use crate::{handlers::self_::check_for_updates, types::BinaryVersion};

use anyhow::{anyhow, bail, Result};
use anyhow::{Result, anyhow, bail};
use clap::{Parser, Subcommand, ValueEnum};
use comfy_table::Table;
pub const TABLE_FORMAT: &str = " ── ══ ── ";
Expand Down
61 changes: 36 additions & 25 deletions src/component/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,23 @@ fn check_path_variables(check: &mut impl FnMut(&str, Result<String, String>)) {

// Check PATH order
let cargo_bin_dir = dirs::home_dir().map(|p| p.join(".cargo/bin"));
if let Some(cargo_bin) = cargo_bin_dir {
if paths.contains(&cargo_bin) {
let suiup_pos = paths.iter().position(|p| p == &default_bin_dir);
let cargo_pos = paths.iter().position(|p| p == &cargo_bin);
if let (Some(s_pos), Some(c_pos)) = (suiup_pos, cargo_pos) {
if s_pos > c_pos {
check("PATH order", Err(format!("WARN: Default binary directory ({}) is after cargo's binary directory ({}). This may cause conflicts if you have also installed sui via `cargo install`.", default_bin_dir.display(), cargo_bin.display())));
} else {
check("PATH order", Ok("is correct".to_string()));
}
if let Some(cargo_bin) = cargo_bin_dir
&& paths.contains(&cargo_bin)
{
let suiup_pos = paths.iter().position(|p| p == &default_bin_dir);
let cargo_pos = paths.iter().position(|p| p == &cargo_bin);
if let (Some(s_pos), Some(c_pos)) = (suiup_pos, cargo_pos) {
if s_pos > c_pos {
check(
"PATH order",
Err(format!(
"WARN: Default binary directory ({}) is after cargo's binary directory ({}). This may cause conflicts if you have also installed sui via `cargo install`.",
default_bin_dir.display(),
cargo_bin.display()
)),
);
} else {
check("PATH order", Ok("is correct".to_string()));
}
}
}
Expand Down Expand Up @@ -239,6 +246,8 @@ async fn check_network_connectivity(check: &mut impl FnMut(&str, Result<String,
#[cfg(test)]
mod tests {
use super::*;
use crate::remove_env_var;
use crate::set_env_var;
use std::fs;
use tempfile::TempDir;

Expand All @@ -253,12 +262,12 @@ mod tests {
#[cfg(windows)]
{
original_data_home = std::env::var("LOCALAPPDATA");
std::env::set_var("LOCALAPPDATA", data_dir.to_str().unwrap());
set_env_var!("LOCALAPPDATA", data_dir.to_str().unwrap());
}
#[cfg(not(windows))]
{
original_data_home = std::env::var("XDG_DATA_HOME");
std::env::set_var("XDG_DATA_HOME", data_dir.to_str().unwrap());
set_env_var!("XDG_DATA_HOME", data_dir.to_str().unwrap());
}

let result = check_suiup_data_dir();
Expand All @@ -269,17 +278,17 @@ mod tests {
#[cfg(windows)]
{
if let Ok(val) = original_data_home {
std::env::set_var("LOCALAPPDATA", val);
set_env_var!("LOCALAPPDATA", val);
} else {
std::env::remove_var("LOCALAPPDATA");
remove_env_var!("LOCALAPPDATA");
}
}
#[cfg(not(windows))]
{
if let Ok(val) = original_data_home {
std::env::set_var("XDG_DATA_HOME", val);
set_env_var!("XDG_DATA_HOME", val);
} else {
std::env::remove_var("XDG_DATA_HOME");
remove_env_var!("XDG_DATA_HOME");
}
}
}
Expand All @@ -294,38 +303,40 @@ mod tests {
#[cfg(windows)]
{
original_data_home = std::env::var("LOCALAPPDATA");
std::env::set_var("LOCALAPPDATA", data_dir.to_str().unwrap());
set_env_var!("LOCALAPPDATA", data_dir.to_str().unwrap());
}
#[cfg(not(windows))]
{
original_data_home = std::env::var("XDG_DATA_HOME");
std::env::set_var("XDG_DATA_HOME", data_dir.to_str().unwrap());
set_env_var!("XDG_DATA_HOME", data_dir.to_str().unwrap());
}

let path = crate::paths::get_suiup_data_dir();
println!("Testing path: {}", path.display());
println!("Path exists: {}", path.exists());
let result = check_suiup_data_dir();
assert!(result.is_err());
assert!(result
.unwrap_err()
.contains("suiup data directory not found"));
assert!(
result
.unwrap_err()
.contains("suiup data directory not found")
);

// Restore original env var
#[cfg(windows)]
{
if let Ok(val) = original_data_home {
std::env::set_var("LOCALAPPDATA", val);
set_env_var!("LOCALAPPDATA", val);
} else {
std::env::remove_var("LOCALAPPDATA");
remove_env_var!("LOCALAPPDATA");
}
}
#[cfg(not(windows))]
{
if let Ok(val) = original_data_home {
std::env::set_var("XDG_DATA_HOME", val);
set_env_var!("XDG_DATA_HOME", val);
} else {
std::env::remove_var("XDG_DATA_HOME");
remove_env_var!("XDG_DATA_HOME");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/component/install.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::{anyhow, Result};
use anyhow::{Result, anyhow};
use std::fs::create_dir_all;

use crate::commands::BinaryName;
Expand Down Expand Up @@ -81,7 +81,7 @@ pub async fn install_component(
match name {
BinaryName::Mvr => Repo::Mvr,
_ => {
return Err(anyhow!("Invalid binary name for standalone installation"))
return Err(anyhow!("Invalid binary name for standalone installation"));
}
},
yes,
Expand Down
2 changes: 1 addition & 1 deletion src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod remove;
use anyhow::Result;

use crate::commands::{
parse_component_with_version, BinaryName, CommandMetadata, ComponentCommands,
BinaryName, CommandMetadata, ComponentCommands, parse_component_with_version,
};

/// ComponentManager handles all component-related operations
Expand Down
12 changes: 6 additions & 6 deletions src/component/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::collections::HashSet;
use std::path::PathBuf;

use anyhow::{anyhow, Result};
use anyhow::{Result, anyhow};
use tracing::debug;

use crate::commands::BinaryName;
Expand All @@ -31,11 +31,11 @@ pub async fn remove_component(binary: BinaryName) -> Result<()> {

// Verify all binaries exist before removing any
for p in &binaries_to_remove {
if let Some(p) = p.path.as_ref() {
if !PathBuf::from(p).exists() {
println!("Binary {p} does not exist. Aborting the command.");
return Ok(());
}
if let Some(p) = p.path.as_ref()
&& !PathBuf::from(p).exists()
{
println!("Binary {p} does not exist. Aborting the command.");
return Ok(());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/fs_utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::{anyhow, Result};
use serde::{de::DeserializeOwned, Serialize};
use anyhow::{Result, anyhow};
use serde::{Serialize, de::DeserializeOwned};
use std::fs::File;
use std::io::Write;
use std::path::Path;
Expand Down
12 changes: 6 additions & 6 deletions src/handlers/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::handlers::release::{
use crate::handlers::version::extract_version_from_release;
use crate::types::Repo;
use crate::{handlers::release::release_list, paths::release_archive_dir, types::Release};
use anyhow::{anyhow, bail, Error};
use anyhow::{Error, anyhow, bail};
use futures_util::StreamExt;
use indicatif::{HumanBytes, ProgressBar, ProgressStyle};
use md5::Context;
use reqwest::{
header::{HeaderMap, HeaderValue, USER_AGENT},
Client,
header::{HeaderMap, HeaderValue, USER_AGENT},
};
use std::fs::File;
use std::io::Read;
Expand Down Expand Up @@ -204,10 +204,10 @@ pub async fn download_file(
let mut request = client.get(url).header("User-Agent", "suiup");

// Add authorization header if token is provided and the URL is from GitHub
if let Some(token) = github_token {
if url.contains("github.com") {
request = request.header("Authorization", format!("token {}", token));
}
if let Some(token) = github_token
&& url.contains("github.com")
{
request = request.header("Authorization", format!("token {}", token));
}

let response = request.send().await?;
Expand Down
10 changes: 7 additions & 3 deletions src/handlers/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::handlers::{extract_component, update_after_install};
use crate::paths::binaries_dir;
use crate::standalone;
use crate::types::{BinaryVersion, InstalledBinaries, Repo};
use anyhow::Error;
use anyhow::anyhow;
use anyhow::bail;
use anyhow::Error;
use indicatif::{ProgressBar, ProgressStyle};
use std::time::Duration;

Expand Down Expand Up @@ -74,7 +74,9 @@ pub async fn install_from_release(
let binary_path = binaries_dir().join(network).join(binary_filename);
install_binary(name, network.to_string(), &version, debug, binary_path, yes)?;
} else {
println!("Binary {name}-{version} already installed. Use `suiup default set` to change the default binary.");
println!(
"Binary {name}-{version} already installed. Use `suiup default set` to change the default binary."
);
}
Ok(())
}
Expand Down Expand Up @@ -195,7 +197,9 @@ pub async fn install_standalone(
)?;
} else {
let version = version.unwrap_or_default();
println!("Binary {binary_name}-{version} already installed. Use `suiup default set {binary_name} {version}` to set the default version to the specified one.");
println!(
"Binary {binary_name}-{version} already installed. Use `suiup default set {binary_name} {version}` to set the default version to the specified one."
);
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use crate::paths::{binaries_dir, get_default_bin_dir, release_archive_dir};
use crate::{paths::default_file_path, types::Version};
use anyhow::anyhow;
use anyhow::Error;
use anyhow::anyhow;
use flate2::read::GzDecoder;
use std::env;
use std::io::Write;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/release.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::Error;
use anyhow::anyhow;
use anyhow::bail;
use anyhow::Error;
use reqwest::header::ETAG;
use reqwest::header::IF_NONE_MATCH;

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/self_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use super::download::detect_os_arch;

use crate::handlers::download::download_file;
use anyhow::{anyhow, Result};
use anyhow::{Result, anyhow};
use std::{fmt::Display, process::Command};
use tokio::task;

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/switch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::{anyhow, bail, Result};
use anyhow::{Result, anyhow, bail};
use tracing::info;

use crate::{
Expand Down
Loading
Loading