Skip to content

Commit

Permalink
run the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed Aug 15, 2024
1 parent 14e492e commit 414890b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 50 deletions.
28 changes: 6 additions & 22 deletions crates/cli/src/commands/install.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use anyhow::Result;
use anyhow::{bail, Result};
use clap::Args;
use log::info;
use serde::Serialize;

use crate::{
updater::{SupportedApp, Updater},
utils::{get_client_arch, get_client_os, Architecture, OperatingSystem},
};
use crate::updater::{SupportedApp, Updater};

#[derive(Args, Debug, Serialize)]
pub struct InstallArgs {
Expand All @@ -16,25 +13,12 @@ pub struct InstallArgs {
/// Specify a specific app to install
#[clap(long = "app")]
app: Option<SupportedApp>,
/// Override the architecture to install
#[clap(long = "arch", hide = true)]
arch: Option<Architecture>,
/// Override the OS to install for
#[clap(long = "os", hide = true)]
os: Option<OperatingSystem>,
}

pub(crate) async fn run_install(arg: InstallArgs) -> Result<()> {
let should_update = arg.update;
let mut updater = Updater::from_current_bin().await?;

let arch = arg
.arch
.map_or_else(|| get_client_arch().to_string(), |arch| arch.to_string());
let os = arg
.os
.map_or_else(|| get_client_os().to_string(), |os| format!("{}", &os));

info!(
"Targeting {} as install directory",
updater.install_path.display()
Expand All @@ -45,13 +29,13 @@ pub(crate) async fn run_install(arg: InstallArgs) -> Result<()> {
true => match should_update {
true => {
info!("{} already present, installing latest", app);
updater.install_latest(app, Some(&os), Some(&arch)).await?;
updater.install_latest(app).await?;
}
false => info!("{} already present, skipping", app),
},
false => {
info!("{} not present, installing", app);
updater.install_latest(app, Some(&os), Some(&arch)).await?;
updater.install_latest(app).await?;
}
}
// TODO: output *only* the installed binary path to stdout
Expand All @@ -63,14 +47,14 @@ pub(crate) async fn run_install(arg: InstallArgs) -> Result<()> {
true => match should_update {
true => {
info!("{} already present, installing latest", app);
updater.install_latest(app, Some(&os), Some(&arch)).await?;
updater.install_latest(app).await?;
}
false => info!("{} already present, skipping", app),
},
false => {
if app.is_default_app() {
info!("{} not present, installing", app);
updater.install_latest(app, Some(&os), Some(&arch)).await?;
updater.install_latest(app).await?;
} else {
info!("{app} not present, skipping, run with --app {app} to install",);
}
Expand Down
11 changes: 2 additions & 9 deletions crates/cli/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,7 @@ impl Updater {
Ok(())
}

pub async fn install_latest(
&mut self,
app: SupportedApp,
_os: Option<&str>,
_arch: Option<&str>,
) -> Result<()> {
pub async fn install_latest(&mut self, app: SupportedApp) -> Result<()> {
self.install_latest_axo(app).await
}

Expand Down Expand Up @@ -736,9 +731,7 @@ mod tests {
"744cc867-ae03-497f-b82a-ee6a4a57e90e".to_string(),
)?;

updater
.install_latest(SupportedApp::Marzano, None, None)
.await?;
updater.install_latest(SupportedApp::Marzano).await?;

let manifest = async_fs::read_to_string(updater.manifest_path.clone()).await?;

Expand Down
19 changes: 0 additions & 19 deletions crates/cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ impl Display for OperatingSystem {
}
}

pub fn get_client_os() -> &'static str {
match std::env::consts::OS {
"macos" => "macos",
"linux" => "linux",
"windows" => "windows",
"darwin" => "macos",
_ => "linux",
}
}

#[derive(Debug, PartialEq, PartialOrd, Clone, Copy, Serialize, Deserialize, ValueEnum)]
pub enum Architecture {
#[serde(rename = "x64")]
Expand All @@ -55,15 +45,6 @@ impl Display for Architecture {
}
}

pub fn get_client_arch() -> &'static str {
match std::env::consts::ARCH {
"x86_64" => "x64",
"aarch64" => "arm64",
// Fall back to x64
_ => "x64",
}
}

#[allow(dead_code)]
pub fn get_random_port() -> Option<u16> {
let listener = TcpListener::bind(SocketAddr::from(([127, 0, 0, 1], 0))).ok()?;
Expand Down

0 comments on commit 414890b

Please sign in to comment.