Skip to content

Commit

Permalink
Alter use of the --verbose flag for fuelup check (#631)
Browse files Browse the repository at this point in the history
* remove --verbose from fuelup check

* remove redundant command modules

* consistency with imports

* fix failing tests

* clippy

* rebase

* optimise check_fuelup and use rayon

* remove unnecessary download progress bar when grabing a toml file

* bring back -v flag to use to show up to date packages

* clean up

* rebase

* clippy

* rebase master

* show number of updates available in default mode

* add verbose flag to tests

* fix tests

* fmt

---------

Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
  • Loading branch information
JoshuaBatty and kayagokalp authored Jun 25, 2024
1 parent e4d7c40 commit 17e8abb
Show file tree
Hide file tree
Showing 44 changed files with 307 additions and 404 deletions.
12 changes: 4 additions & 8 deletions component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,10 @@ impl Components {
}

pub fn collect_plugin_executables() -> Result<Vec<String>> {
let plugins = Self::collect_plugins()?;
let mut executables = vec![];

for plugin in plugins.iter() {
executables.extend(plugin.executables.clone().into_iter())
}

let executables = Self::collect_plugins()?
.iter()
.flat_map(|p| p.executables.clone())
.collect();
Ok(executables)
}

Expand All @@ -195,7 +192,6 @@ impl Components {
if let Some(forc) = components.component.get(FORC) {
return forc.executables.contains(&plugin_name.to_string());
};

false
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ fn construct_channel_url(desc: &DistToolchainDescription) -> Result<String> {
match desc.name {
DistToolchainName::Latest => {
if let Some(date) = desc.date {
url.push_str(&format!("channels/latest/channel-fuel-latest-{date}.toml"))
url.push_str(&format!("channels/latest/channel-fuel-latest-{date}.toml"));
} else {
url.push_str(CHANNEL_LATEST_FILE_NAME)
url.push_str(CHANNEL_LATEST_FILE_NAME);
}
}

Expand All @@ -83,7 +83,7 @@ fn construct_channel_url(desc: &DistToolchainDescription) -> Result<String> {
url.push_str(&format_nightly_url(&date)?);
url.push('/');
}
url.push_str(CHANNEL_NIGHTLY_FILE_NAME)
url.push_str(CHANNEL_NIGHTLY_FILE_NAME);
}
DistToolchainName::Beta1 => url.push_str(CHANNEL_BETA_1_FILE_NAME),
DistToolchainName::Beta2 => url.push_str(CHANNEL_BETA_2_FILE_NAME),
Expand All @@ -100,12 +100,10 @@ fn construct_channel_url(desc: &DistToolchainDescription) -> Result<String> {
impl Channel {
pub fn from_dist_channel(desc: &DistToolchainDescription) -> Result<Self> {
let channel_url = construct_channel_url(desc)?;

let toml = match download(&channel_url) {
Ok(t) => String::from_utf8(t)?,
Err(_) => bail!("Could not read {}", &channel_url),
};

Self::from_toml(&toml)
}

Expand Down
4 changes: 1 addition & 3 deletions src/commands/completions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::ops::fuelup_completions;
use anyhow::Result;
use clap::Parser;
use clap_complete::Shell;

use crate::ops::fuelup_completions;

/// Generate tab-completion scripts for your shell
#[derive(Debug, Parser)]
pub struct CompletionsCommand {
Expand All @@ -14,6 +13,5 @@ pub struct CompletionsCommand {

pub fn exec(command: CompletionsCommand) -> Result<()> {
fuelup_completions::completions(command)?;

Ok(())
}
11 changes: 3 additions & 8 deletions src/commands/component.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use crate::ops::fuelup_component::{add::add, list::list, remove::remove};
use anyhow::Result;
use clap::Parser;

use crate::ops::fuelup_component::{add::add, list::list, remove::remove};

#[derive(Debug, Parser)]
pub enum ComponentCommand {
/// Add a component to the currently active custom toolchain.
Add(AddCommand),
/// Remove a component from the currently active custom toolchain
Remove(RemoveCommand),
/// List installed and installable components
List(ListCommand),
List,
}

#[derive(Debug, Parser)]
Expand All @@ -25,15 +24,11 @@ pub struct RemoveCommand {
pub component: String,
}

#[derive(Debug, Parser)]
pub struct ListCommand {}

pub fn exec(command: ComponentCommand) -> Result<()> {
match command {
ComponentCommand::Add(command) => add(command)?,
ComponentCommand::Remove(command) => remove(command)?,
ComponentCommand::List(command) => list(command)?,
ComponentCommand::List => list()?,
};

Ok(())
}
4 changes: 1 addition & 3 deletions src/commands/default.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::ops::fuelup_default;
use anyhow::Result;
use clap::Parser;

use crate::ops::fuelup_default;

#[derive(Debug, Parser)]
pub struct DefaultCommand {
/// Set the default toolchain.
Expand All @@ -11,6 +10,5 @@ pub struct DefaultCommand {

pub fn exec(command: DefaultCommand) -> Result<()> {
let DefaultCommand { toolchain } = command;

fuelup_default::default(toolchain)
}
5 changes: 1 addition & 4 deletions src/commands/fuelup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::ops::fuelup_self::{self_uninstall, self_update};
use anyhow::{bail, Result};
use clap::Parser;

use crate::ops::fuelup_self::{self_uninstall, self_update};

#[derive(Debug, Parser)]
pub enum FuelupCommand {
/// Updates fuelup
Expand All @@ -27,14 +26,12 @@ pub fn update_exec(force: bool) -> Result<()> {
if let Err(e) = self_update(force) {
bail!("fuelup failed to update itself: {}", e)
};

Ok(())
}

pub fn remove_exec(force: bool) -> Result<()> {
if let Err(e) = self_uninstall(force) {
bail!("fuelup failed to update itself: {}", e)
};

Ok(())
}
2 changes: 0 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ pub mod completions;
pub mod component;
pub mod default;
pub mod fuelup;
pub mod show;
pub mod toolchain;
pub mod update;
pub mod upgrade;
11 changes: 0 additions & 11 deletions src/commands/show.rs

This file was deleted.

9 changes: 3 additions & 6 deletions src/commands/toolchain.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use anyhow::{bail, Result};
use clap::Parser;

use crate::ops::fuelup_toolchain::install::install;
use crate::ops::fuelup_toolchain::new::new;
use crate::ops::fuelup_toolchain::uninstall::uninstall;
use crate::ops::fuelup_toolchain::{install::install, new::new, uninstall::uninstall};
use crate::target_triple::TargetTriple;
use crate::toolchain::RESERVED_TOOLCHAIN_NAMES;
use anyhow::{bail, Result};
use clap::Parser;

#[derive(Debug, Parser)]
pub enum ToolchainCommand {
Expand Down
13 changes: 0 additions & 13 deletions src/commands/update.rs

This file was deleted.

4 changes: 1 addition & 3 deletions src/commands/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::ops::fuelup_upgrade;
use anyhow::Result;
use clap::Parser;

use crate::ops::fuelup_upgrade;

#[derive(Debug, Parser)]
pub struct UpgradeCommand {
#[clap(long, short)]
Expand All @@ -11,6 +10,5 @@ pub struct UpgradeCommand {

pub fn exec(force: bool) -> Result<()> {
fuelup_upgrade::upgrade(force)?;

Ok(())
}
15 changes: 5 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use std::fs;
use std::path::PathBuf;

use anyhow::Result;
use std::io;

use crate::fmt::format_toolchain_with_target;
use crate::path::toolchains_dir;
use crate::toolchain::RESERVED_TOOLCHAIN_NAMES;
use anyhow::Result;
use std::{fs, io, path::PathBuf};

pub struct Config {
toolchains_dir: PathBuf,
Expand All @@ -33,9 +29,9 @@ impl Config {
.iter()
.any(|t| toolchain == format_toolchain_with_target(t))
{
toolchains.push(toolchain)
toolchains.push(toolchain);
} else {
custom_toolchains.push(toolchain)
custom_toolchains.push(toolchain);
}
}

Expand All @@ -61,10 +57,9 @@ impl Config {
for name in RESERVED_TOOLCHAIN_NAMES {
let dist_toolchain = format_toolchain_with_target(name);
if installed_toolchains.contains(&dist_toolchain) {
dist_toolchains.push(name.to_string())
dist_toolchains.push(name.to_string());
}
}

Ok(dist_toolchains)
} else {
Ok(Vec::new())
Expand Down
3 changes: 1 addition & 2 deletions src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::io::{self, Write};

use crate::target_triple::TargetTriple;
use ansi_term::Colour;
use ansiterm::Style;
use std::io::{self, Write};
use tracing::info;

pub fn println_error<X: Into<String>>(txt: X) {
Expand Down
32 changes: 14 additions & 18 deletions src/fuelup_cli.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use anyhow::Result;
use clap::Parser;

use crate::commands::show::ShowCommand;
use crate::commands::{
check, completions, component, default, fuelup, show, toolchain, update, upgrade,
check::{self, CheckCommand},
completions::{self, CompletionsCommand},
component::{self, ComponentCommand},
default::{self, DefaultCommand},
fuelup::{self, FuelupCommand},
toolchain::{self, ToolchainCommand},
upgrade::{self, UpgradeCommand},
};

use crate::commands::check::CheckCommand;
use crate::commands::completions::CompletionsCommand;
use crate::commands::component::ComponentCommand;
use crate::commands::default::DefaultCommand;
use crate::commands::fuelup::FuelupCommand;
use crate::commands::toolchain::ToolchainCommand;
use crate::commands::update::UpdateCommand;
use crate::commands::upgrade::UpgradeCommand;
use crate::ops::{fuelup_show, fuelup_update};
use anyhow::Result;
use clap::Parser;

#[derive(Debug, Parser)]
#[clap(name = "fuelup", about = "Fuel Toolchain Manager", version)]
Expand All @@ -40,9 +36,9 @@ enum Commands {
#[clap(subcommand)]
Toolchain(ToolchainCommand),
/// Show the active and installed toolchains, as well as the host and fuelup home
Show(ShowCommand),
Show,
/// Updates the distributable toolchains, if already installed
Update(UpdateCommand),
Update,
/// Updates fuelup itself, switches to the `latest` channel and updates components in all channels.
Upgrade(UpgradeCommand),
}
Expand All @@ -59,9 +55,9 @@ pub fn fuelup_cli() -> Result<()> {
FuelupCommand::Update(update) => fuelup::update_exec(update.force),
FuelupCommand::Uninstall(remove) => fuelup::remove_exec(remove.force),
},
Commands::Show(_command) => show::exec(),
Commands::Show => fuelup_show::show(),
Commands::Toolchain(command) => toolchain::exec(command),
Commands::Update(_command) => update::exec(),
Commands::Update => fuelup_update::update(),
Commands::Upgrade(command) => upgrade::exec(command.force),
}
}
Loading

0 comments on commit 17e8abb

Please sign in to comment.