Skip to content

Commit

Permalink
feat: add upgrade command to auto update fuelup, switch to latest and…
Browse files Browse the repository at this point in the history
… update installed channels (#625)

* feat: add upgrade command to auto update fuelup, switch to latest and update installed channels

* test: add upgrade test
  • Loading branch information
kayagokalp authored Jun 7, 2024
1 parent 90f9004 commit 27fe0cf
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pub mod fuelup;
pub mod show;
pub mod toolchain;
pub mod update;
pub mod upgrade;
16 changes: 16 additions & 0 deletions src/commands/upgrade.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use anyhow::Result;
use clap::Parser;

use crate::ops::fuelup_upgrade;

#[derive(Debug, Parser)]
pub struct UpgradeCommand {
#[clap(long, short)]
pub force: bool,
}

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

Ok(())
}
8 changes: 7 additions & 1 deletion src/fuelup_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use anyhow::Result;
use clap::Parser;

use crate::commands::show::ShowCommand;
use crate::commands::{check, completions, component, default, fuelup, show, toolchain, update};
use crate::commands::{
check, completions, component, default, fuelup, show, toolchain, update, upgrade,
};

use crate::commands::check::CheckCommand;
use crate::commands::completions::CompletionsCommand;
Expand All @@ -11,6 +13,7 @@ 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;

#[derive(Debug, Parser)]
#[clap(name = "fuelup", about = "Fuel Toolchain Manager", version)]
Expand Down Expand Up @@ -40,6 +43,8 @@ enum Commands {
Show(ShowCommand),
/// Updates the distributable toolchains, if already installed
Update(UpdateCommand),
/// Updates fuelup itself, switches to the `latest` channel and updates components in all channels.
Upgrade(UpgradeCommand),
}

pub fn fuelup_cli() -> Result<()> {
Expand All @@ -57,5 +62,6 @@ pub fn fuelup_cli() -> Result<()> {
Commands::Show(_command) => show::exec(),
Commands::Toolchain(command) => toolchain::exec(command),
Commands::Update(_command) => update::exec(),
Commands::Upgrade(command) => upgrade::exec(command.force),
}
}
13 changes: 13 additions & 0 deletions src/ops/fuelup_upgrade.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use super::{fuelup_default, fuelup_self, fuelup_update};
use crate::channel::LATEST;
use anyhow::Result;

pub fn upgrade(force: bool) -> Result<()> {
// self update
fuelup_self::self_update(force)?;
// switch to 'latest' channel.
fuelup_default::default(Some(LATEST.to_owned()))?;
// update channels
fuelup_update::update()?;
Ok(())
}
1 change: 1 addition & 0 deletions src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pub mod fuelup_self;
pub mod fuelup_show;
pub mod fuelup_toolchain;
pub mod fuelup_update;
pub mod fuelup_upgrade;
15 changes: 15 additions & 0 deletions tests/upgrade.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use anyhow::Result;
use testcfg::FuelupState;

pub mod testcfg;

#[test]
fn fuelup_upgrade() -> Result<()> {
testcfg::setup(FuelupState::LatestToolchainInstalled, &|cfg| {
let output = cfg.fuelup(&["upgrade"]);
let expected_stdout_starts_with = "Already up to date";
assert!(output.stdout.contains(expected_stdout_starts_with));
})?;

Ok(())
}

0 comments on commit 27fe0cf

Please sign in to comment.