diff --git a/src/commands/env/mod.rs b/src/commands/env/mod.rs index e1e54f4..f5dad6f 100644 --- a/src/commands/env/mod.rs +++ b/src/commands/env/mod.rs @@ -4,8 +4,8 @@ use crate::app::App; mod docker; mod gitignore; -mod workflow_test; mod workflow_packwiz; +mod workflow_test; #[derive(clap::Subcommand, Clone, Copy)] pub enum Commands { diff --git a/src/commands/env/workflow_packwiz.rs b/src/commands/env/workflow_packwiz.rs index 180d8f1..20a01c7 100644 --- a/src/commands/env/workflow_packwiz.rs +++ b/src/commands/env/workflow_packwiz.rs @@ -1,12 +1,14 @@ -use std::{path::Path, io::Write}; +use std::{io::Write, path::Path}; use anyhow::Result; use std::fs::File; -use crate::{util::env::get_git_root, app::App}; +use crate::{app::App, util::env::get_git_root}; pub fn run(app: &App) -> Result<()> { - let path = Path::new(&get_git_root()?.unwrap_or(".".to_owned())).join(".github").join("workflows"); + let path = Path::new(&get_git_root()?.unwrap_or(".".to_owned())) + .join(".github") + .join("workflows"); let mut f = File::create(path.join("packwiz.yml"))?; f.write_all(include_bytes!("../../../res/workflows/packwiz.yml"))?; diff --git a/src/commands/env/workflow_test.rs b/src/commands/env/workflow_test.rs index 89bd15d..ca53bea 100644 --- a/src/commands/env/workflow_test.rs +++ b/src/commands/env/workflow_test.rs @@ -1,12 +1,14 @@ -use std::{path::Path, io::Write}; +use std::{io::Write, path::Path}; use anyhow::Result; use std::fs::File; -use crate::{util::env::get_git_root, app::App}; +use crate::{app::App, util::env::get_git_root}; pub fn run(app: &App) -> Result<()> { - let path = Path::new(&get_git_root()?.unwrap_or(".".to_owned())).join(".github").join("workflows"); + let path = Path::new(&get_git_root()?.unwrap_or(".".to_owned())) + .join(".github") + .join("workflows"); let mut f = File::create(path.join("test.yml"))?; f.write_all(include_bytes!("../../../res/workflows/test.yml"))?; diff --git a/src/sources/modrinth.rs b/src/sources/modrinth.rs index f3f0592..2e0c5cf 100644 --- a/src/sources/modrinth.rs +++ b/src/sources/modrinth.rs @@ -103,7 +103,6 @@ pub struct ModrinthFile { // file_type omitted } - #[async_trait] pub trait ModrinthWaitRatelimit { async fn wait_ratelimit(self) -> Result; diff --git a/src/sources/vanilla.rs b/src/sources/vanilla.rs index f9886f2..8706306 100644 --- a/src/sources/vanilla.rs +++ b/src/sources/vanilla.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use anyhow::{anyhow, Result, Context}; +use anyhow::{anyhow, Context, Result}; use crate::app::{App, CacheStrategy, ResolvedFile}; @@ -17,23 +17,22 @@ impl<'a> VanillaAPI<'a> { } pub async fn resolve_source(&self, version: &str) -> Result { - let version_manifest = mcapi::vanilla::fetch_version_manifest(&self.0.http_client).await + let version_manifest = mcapi::vanilla::fetch_version_manifest(&self.0.http_client) + .await .context("Fetching version manifest")?; let version = match version { - "latest" => { - version_manifest - .fetch_latest_release(&self.0.http_client) - .await - .context("Fetching latest release")? - } - "latest-snapshot" => { - version_manifest - .fetch_latest_snapshot(&self.0.http_client) - .await - .context("Fetching latest snapshot")? - } - id => version_manifest.fetch(id, &self.0.http_client).await + "latest" => version_manifest + .fetch_latest_release(&self.0.http_client) + .await + .context("Fetching latest release")?, + "latest-snapshot" => version_manifest + .fetch_latest_snapshot(&self.0.http_client) + .await + .context("Fetching latest snapshot")?, + id => version_manifest + .fetch(id, &self.0.http_client) + .await .context(format!("Fetching release {id}"))?, }; diff --git a/src/util/env.rs b/src/util/env.rs index 73d2d8a..745eaf6 100644 --- a/src/util/env.rs +++ b/src/util/env.rs @@ -7,14 +7,14 @@ use std::{ use anyhow::{anyhow, Result}; use pathdiff::diff_paths; -pub fn try_get_url(folder: &PathBuf) -> Result { +pub fn try_get_url(folder: &Path) -> Result { let repo_url = get_git_remote()?.ok_or(anyhow!("cant get repo url"))?; let root = get_git_root()?.ok_or(anyhow!("cant get repo root"))?; let branch = get_git_branch()?.ok_or(anyhow!("cant get repo branch"))?; let root_path = Path::new(&root).canonicalize()?; - let diff = diff_paths(folder.canonicalize()?, &root_path).ok_or(anyhow!("cant diff paths"))?; + let diff = diff_paths(folder.canonicalize()?, root_path).ok_or(anyhow!("cant diff paths"))?; let repo = if repo_url.starts_with("https") { repo_url.strip_prefix("https://github.com/") diff --git a/src/util/logger.rs b/src/util/logger.rs deleted file mode 100644 index 37edaa4..0000000 --- a/src/util/logger.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![allow(dead_code)] - -#[derive(Debug)] -pub enum Logger { - Main, - - Task { indent: usize }, - - List { indent: usize, len: usize }, -} - -impl Logger { - pub fn new() -> Self { - Self::Main - } - - pub fn log(&self, text: &str) { - let space = " "; - let indent = self.get_indent(); - - println!("{space:indent$}{text}",); - } - - pub fn item(&self, idx: usize, text: &str) { - match self { - Self::List { indent, len } => { - println!( - "{:indent$}({:idx_w$}/{len}) {text}", - " ", - idx + 1, - idx_w = len.to_string().len() - ); - } - - _ => unimplemented!(), - } - } - - pub fn list(&self, len: usize) -> Logger { - Logger::List { - indent: self.get_indent(), - len, - } - } - - pub fn task(&self, name: &str, indent: usize) -> Logger { - self.log(name); - - Logger::Task { - indent: self.get_indent() + indent, - } - } - - pub fn get_indent(&self) -> usize { - match self { - Self::Main => 0, - Self::Task { indent } => *indent, - Self::List { indent, len, .. } => indent + (len.to_string().len() * 2) + 4, - } - } -} diff --git a/src/util/mod.rs b/src/util/mod.rs index 9de8a26..0967e26 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -4,7 +4,6 @@ use anyhow::Result; use regex::Regex; pub mod env; -pub mod logger; pub mod maven_import; pub mod md;