Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MordechaiHadad committed Nov 17, 2023
1 parent 9514f2a commit 4ec21f3
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 68 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/format.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub async fn start(config: Config) -> Result<()> {
InstallResult::NightlyIsUpdated => {
info!("Nightly up to date!");
}
InstallResult::GivenNightlyRollback => ()
InstallResult::GivenNightlyRollback => (),
}
}
Cli::Sync => {
Expand Down
26 changes: 18 additions & 8 deletions src/handlers/install_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::Config;
use crate::github_requests::{get_upstream_nightly, UpstreamVersion, get_commits_for_nightly};
use crate::github_requests::{get_commits_for_nightly, get_upstream_nightly, UpstreamVersion};
use crate::helpers::directories::get_downloads_directory;
use crate::helpers::version::nightly::produce_nightly_vec;
use crate::helpers::version::types::{LocalVersion, ParsedVersion, VersionType};
Expand All @@ -11,10 +11,10 @@ use reqwest::Client;
use std::cmp::min;
use std::env;
use std::path::Path;
use std::process::Stdio;
use tokio::fs::File;
use tokio::io::AsyncWriteExt;
use tokio::{fs, process::Command};
use std::process::Stdio;
use tracing::info;
use yansi::Paint;

Expand All @@ -26,7 +26,7 @@ pub async fn start(
config: &Config,
) -> Result<InstallResult> {
if version.version_type == VersionType::NightlyRollback {
return Ok(InstallResult::GivenNightlyRollback)
return Ok(InstallResult::GivenNightlyRollback);
}

let root = directories::get_downloads_directory(config).await?;
Expand All @@ -36,7 +36,6 @@ pub async fn start(

let is_version_installed =
helpers::version::is_version_installed(&version.tag_name, config).await?;


if is_version_installed && version.version_type != VersionType::Nightly {
return Ok(InstallResult::VersionAlreadyInstalled);
Expand Down Expand Up @@ -70,7 +69,9 @@ pub async fn start(
}

let downloaded_file = match version.version_type {
VersionType::Normal | VersionType::Latest => download_version(client, version, root, config).await,
VersionType::Normal | VersionType::Latest => {
download_version(client, version, root, config).await
}
VersionType::Nightly => {
if config.enable_release_build == Some(true) {
handle_building_from_source(version, config).await
Expand Down Expand Up @@ -146,7 +147,13 @@ async fn handle_rollback(config: &Config) -> Result<()> {

let nightly_file = fs::read_to_string("nightly/bob.json").await?;
let mut json_struct: UpstreamVersion = serde_json::from_str(&nightly_file)?;
let id: String = json_struct.target_commitish.as_ref().unwrap().chars().take(7).collect();
let id: String = json_struct
.target_commitish
.as_ref()
.unwrap()
.chars()
.take(7)
.collect();

info!("Creating rollback: nightly-{id}");
filesystem::copy_dir("nightly", format!("nightly-{id}")).await?;
Expand Down Expand Up @@ -356,10 +363,13 @@ async fn handle_building_from_source(
.arg(&version.non_parsed_string)
.spawn()?
.wait()
.await?.success();
.await?
.success();

if !fetch_successful {
return Err(anyhow!("fetching remote failed, try providing the full commit hash"));
return Err(anyhow!(
"fetching remote failed, try providing the full commit hash"
));
}

// checkout fetched files
Expand Down
6 changes: 4 additions & 2 deletions src/handlers/list_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use regex::Regex;
use std::fs;
use yansi::Paint;

use crate::{config::Config, helpers::{directories, self, version::nightly::produce_nightly_vec}};

use crate::{
config::Config,
helpers::{self, directories, version::nightly::produce_nightly_vec},
};

pub async fn start(config: Config) -> Result<()> {
let downloads_dir = directories::get_downloads_directory(&config).await?;
Expand Down
5 changes: 2 additions & 3 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ pub mod list_handler;
pub mod rollback_handler;
pub mod sync_handler;
pub mod uninstall_handler;
pub mod use_handler;
pub mod update_handler;
pub mod use_handler;

use super::version::types::LocalVersion;


pub enum InstallResult {
InstallationSuccess(String),
VersionAlreadyInstalled,
NightlyIsUpdated,
GivenNightlyRollback
GivenNightlyRollback,
}

#[derive(PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/rollback_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub async fn start(config: Config) -> Result<()> {
&ParsedVersion {
tag_name: name_list[i].clone(),
version_type: crate::helpers::version::types::VersionType::Normal,
non_parsed_string: "".to_string()
non_parsed_string: "".to_string(),
},
)
.await?;
Expand Down
6 changes: 4 additions & 2 deletions src/handlers/uninstall_handler.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

use anyhow::{anyhow, Result};
use reqwest::Client;
use tokio::fs;
use tracing::{info, warn};

use crate::{config::Config, helpers::{self, directories}};
use crate::{
config::Config,
helpers::{self, directories},
};

pub async fn start(version: &str, config: Config) -> Result<()> {
let client = Client::new();
Expand Down
10 changes: 7 additions & 3 deletions src/handlers/update_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ pub async fn start(data: Update, client: &Client, config: Config) -> Result<()>
if is_version_installed(&stable.tag_name, &config).await? {
match install_handler::start(&mut stable, client, &config).await? {
InstallResult::VersionAlreadyInstalled => info!("Stable is already updated!"),
InstallResult::InstallationSuccess(_) | InstallResult::NightlyIsUpdated | InstallResult::GivenNightlyRollback => (),
InstallResult::InstallationSuccess(_)
| InstallResult::NightlyIsUpdated
| InstallResult::GivenNightlyRollback => (),
}
did_update = true;
}
Expand All @@ -23,7 +25,9 @@ pub async fn start(data: Update, client: &Client, config: Config) -> Result<()>
let mut nightly = crate::version::parse_version_type(client, "nightly").await?;
match install_handler::start(&mut nightly, client, &config).await? {
InstallResult::NightlyIsUpdated => info!("Nightly is already updated!"),
InstallResult::InstallationSuccess(_) | InstallResult::VersionAlreadyInstalled | InstallResult::GivenNightlyRollback => ()
InstallResult::InstallationSuccess(_)
| InstallResult::VersionAlreadyInstalled
| InstallResult::GivenNightlyRollback => (),
}

did_update = true;
Expand All @@ -41,7 +45,7 @@ pub async fn start(data: Update, client: &Client, config: Config) -> Result<()>
if !is_version_installed(&version.tag_name, &config).await? {
warn!("{} is not installed.", version.non_parsed_string);
return Ok(());
}
}
match install_handler::start(&mut version, client, &config).await? {
InstallResult::NightlyIsUpdated => info!("Nightly is already updated!"),
InstallResult::VersionAlreadyInstalled => info!("Stable is already updated!"),
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/directories.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Result};
use std::path::PathBuf;
use std::fs;
use std::path::PathBuf;

use crate::config::Config;

Expand Down
7 changes: 3 additions & 4 deletions src/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
pub mod filesystem;
pub mod directories;
pub mod version;
pub mod unarchive;
pub mod filesystem;
pub mod sync;
pub mod unarchive;
pub mod version;

use anyhow::{anyhow, Result};
use tokio::process::Command;


pub fn get_file_type() -> &'static str {
if cfg!(target_family = "windows") {
"zip"
Expand Down
7 changes: 5 additions & 2 deletions src/helpers/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ pub mod types;

use self::types::{ParsedVersion, VersionType};
use super::directories;
use crate::{config::Config, github_requests::{UpstreamVersion, deserialize_response}};
use crate::{
config::Config,
github_requests::{deserialize_response, UpstreamVersion},
};
use anyhow::{anyhow, Context, Result};
use regex::Regex;
use reqwest::Client;
Expand Down Expand Up @@ -125,7 +128,7 @@ async fn search_stable_version(client: &Client) -> Result<String> {
.text()
.await?;

let versions: Vec<UpstreamVersion> = deserialize_response(response, )?;
let versions: Vec<UpstreamVersion> = deserialize_response(response)?;
let stable_release = versions
.iter()
.find(|v| v.tag_name == "stable")
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/version/nightly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use regex::Regex;
use tokio::fs;

use super::types::LocalNightly;
use crate::{config::Config, helpers::directories, github_requests::UpstreamVersion};

use crate::{config::Config, github_requests::UpstreamVersion, helpers::directories};

pub async fn get_local_nightly(config: &Config) -> Result<UpstreamVersion> {
let downloads_dir = directories::get_downloads_directory(config).await?;
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/version/types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::path::PathBuf;
use crate::github_requests::UpstreamVersion;
use std::path::PathBuf;

pub struct ParsedVersion {
pub tag_name: String,
pub version_type: VersionType,
pub non_parsed_string: String
pub non_parsed_string: String,
}

#[derive(PartialEq, Eq, Debug)]
Expand All @@ -13,7 +13,7 @@ pub enum VersionType {
Latest,
Nightly,
Hash,
NightlyRollback
NightlyRollback,
}

#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod cli;
mod config;
pub mod github_requests;
mod handlers;
mod helpers;
pub mod github_requests;

extern crate core;

Expand Down

0 comments on commit 4ec21f3

Please sign in to comment.