Skip to content

Commit

Permalink
refactor: bump cargo deps; some light code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
amyavi committed Jan 17, 2024
1 parent 05da462 commit db1d1c5
Show file tree
Hide file tree
Showing 32 changed files with 639 additions and 728 deletions.
1,104 changes: 514 additions & 590 deletions Cargo.lock

Large diffs are not rendered by default.

55 changes: 30 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "mcman"
version = "0.4.4"
edition = "2021"
rust-version = "1.75"
repository = "https://github.com/ParadigmMC/mcman"
homepage = "https://paradigmmc.github.io/mcman/"
authors = ["ParadigmMC"]
Expand All @@ -14,45 +15,49 @@ keywords = [
categories = ["command-line-utilities", "config"]

[profile.release]
debug = false
strip = true
lto = true
opt-level = "s"

[lints.clippy]
all = "deny"
pedantic = "warn"
missing_docs_in_private_items = "allow"
missing_errors_doc = "allow"
module_name_repetitions = "allow"
struct_excessive_bools = "allow"

[dependencies]
anyhow = "1.0"
clap = { version = "4.3", features = [ "derive" ] }
cached = "0.47"
clap = { version = "4.4", features = ["derive"] }
confique = { version = "0.2", default-features = false, features = ["toml"] }
console = "0.15"
dialoguer = "0.10"
futures = "0.3"
indexmap = "2.0"
dialoguer = "0.11"
digest = "0.10"
dirs = "5.0"
glob = "0.3"
hex = "0.4"
indexmap = "2.1"
indicatif = "0.17"
mcapi = { git = "https://github.com/ParadigmMC/mcapi.git" }
#mcapi = { path = "../mcapi" }
md-5 = "0.10"
notify-debouncer-mini = { version = "0.4" }
opener = "0.6"
pathdiff = { git = "https://github.com/Manishearth/pathdiff.git" }
rpackwiz = { git = "https://github.com/vgskye/rpackwiz.git" }
regex = "1.9"
regex = "1.10"
reqwest = { version = "0.11", features = ["json", "stream", "rustls-tls"], default-features = false }
roxmltree = "0.19"
semver = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tempfile = "3.7"
tokio = { version = "1.29", features = ["macros", "rt", "rt-multi-thread", "process", "signal", "io-std"] }
tokio-util = { version = "0.7", features = ["io"] }
toml = "0.7"
walkdir = "2.3"
zip = "0.6"
sha1 = "0.10"
sha2 = "0.10"
md-5 = "0.10"
notify-debouncer-mini = { version = "0.4" }
glob = "0.3"
async-trait = "0.1"
roxmltree = "0.18"
cached = "0.44"
dirs = "5.0.1"
base16ct = { version = "0.2", features = ["alloc"] }
digest = "0.10"
opener = "0.6"
confique = { version = "0.2.5", default-features = false, features = ["toml"] }
rayon = "1.8.0"
tempfile = "3.9"
tokio = { version = "1.35", features = ["macros", "rt", "rt-multi-thread", "process", "signal", "io-std"] }
tokio-stream = "0.1"
tokio-util = { version = "0.7", features = ["io"] }
toml = "0.8"
walkdir = "2.4"
zip = "0.6"
3 changes: 1 addition & 2 deletions res/workflows/packwiz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:

- name: Install mcman
run: |
wget https://github.com/ParadigmMC/mcman/releases/latest/download/mcman
sudo mv ./mcman /usr/bin/
sudo curl -L -o /usr/bin/mcman https://github.com/ParadigmMC/mcman/releases/latest/download/mcman
sudo chmod +x /usr/bin/mcman
- name: Run mcman export packwiz
Expand Down
3 changes: 1 addition & 2 deletions res/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ jobs:
mcman-
- name: Install mcman
run: |
wget https://github.com/ParadigmMC/mcman/releases/latest/download/mcman
sudo mv ./mcman /usr/bin/
sudo curl -L -o /usr/bin/mcman https://github.com/ParadigmMC/mcman/releases/latest/download/mcman
sudo chmod +x /usr/bin/mcman
- name: Test the server
id: test
Expand Down
6 changes: 3 additions & 3 deletions src/app/downloading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use std::{fmt::Debug, path::PathBuf, time::Duration};

use anyhow::{bail, Context, Result};
use digest::{Digest, DynDigest};
use futures::StreamExt;
use indicatif::{ProgressBar, ProgressStyle};
use md5::Md5;
use sha1::Sha1;
use sha2::{Sha256, Sha512};
use tokio::{fs::File, io::BufWriter};
use tokio_stream::StreamExt;
use tokio_util::io::ReaderStream;

use crate::util::SelectItem;
Expand Down Expand Up @@ -105,7 +105,7 @@ impl App {

let validate_hash = |hasher: Option<(String, Box<dyn DynDigest>, String)>| {
if let Some((hash_name, digest, resolved_hash)) = hasher {
let stream_hash = base16ct::lower::encode_string(&digest.finalize());
let stream_hash = hex::encode(&digest.finalize());

if resolved_hash == stream_hash {
self.dbg("hash check success");
Expand Down Expand Up @@ -225,7 +225,7 @@ impl App {
progress_bar.set_length(cached_size);
progress_bar.set_prefix(ProgressPrefix::Copying);

let mut cache_file = File::open(&cached).await.context(format!(
let cache_file = File::open(&cached).await.context(format!(
"Opening file '{}' from cache dir",
cached.to_string_lossy()
))?;
Expand Down
10 changes: 5 additions & 5 deletions src/app/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::{collections::HashMap, path::PathBuf};

use anyhow::{Context, Result};
use digest::{Digest, DynDigest};
use futures::StreamExt;
use indicatif::ProgressBar;
use sha2::Sha256;
use tokio::{
fs::File,
io::{AsyncRead, AsyncWrite},
};
use tokio_stream::StreamExt;
use tokio_util::io::ReaderStream;

use super::{App, ResolvedFile};
Expand Down Expand Up @@ -52,7 +52,7 @@ impl App {
.with_message(format!("Calculating hash for {}", resolved.filename)),
);

let mut file = File::open(&file_path)
let file = File::open(&file_path)
.await
.context(format!("Opening file '{}'", file_path.display()))?;

Expand All @@ -72,7 +72,7 @@ impl App {

pb.finish_and_clear();

let stream_hash = base16ct::lower::encode_string(&digester.finalize());
let stream_hash = hex::encode(&digester.finalize());

Ok((preferred_hash.to_owned(), stream_hash))
}
Expand All @@ -95,14 +95,14 @@ impl App {
tokio::io::copy(&mut item.as_ref(), dest).await?;
}

Ok(base16ct::lower::encode_string(&digester.finalize()))
Ok(hex::encode(&digester.finalize()))
}

pub fn hash_sha256(contents: &str) -> String {
let mut hasher = Sha256::new();

Digest::update(&mut hasher, contents);

base16ct::lower::encode_string(&hasher.finalize())
hex::encode(hasher.finalize())
}
}
2 changes: 0 additions & 2 deletions src/app/resolvable.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::collections::HashMap;

use anyhow::Result;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};

use super::App;

#[async_trait]
pub trait Resolvable {
async fn resolve_source(&self, app: &App) -> Result<ResolvedFile>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub enum Commands {
Modrinth(modrinth::Args),
}

pub async fn run(mut app: App, args: Commands) -> Result<()> {
pub async fn run(app: App, args: Commands) -> Result<()> {
match args {
Commands::Modrinth(args) => modrinth::run(app, args).await?,
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ impl<'a> DevArgs {
}

pub async fn run(app: App, args: DevArgs) -> Result<()> {
let mut dev_session = args.create_dev_session(&app)?;

let dev_session = args.create_dev_session(&app)?;
dev_session.start().await?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/commands/env/workflow_packwiz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fs::File;
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()))
let path = Path::new(&get_git_root().unwrap_or(".".to_owned()))
.join(".github")
.join("workflows");

Expand Down
2 changes: 1 addition & 1 deletion src/commands/env/workflow_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fs::File;
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()))
let path = Path::new(&get_git_root().unwrap_or(".".to_owned()))
.join(".github")
.join("workflows");

Expand Down
2 changes: 1 addition & 1 deletion src/commands/export/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum Commands {
Packwiz(packwiz::Args),
}

pub async fn run(mut app: App, commands: Commands) -> Result<()> {
pub async fn run(app: App, commands: Commands) -> Result<()> {
match commands {
Commands::Mrpack(args) => mrpack::run(app, args).await,
Commands::Packwiz(args) => packwiz::run(app, args).await,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/import/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Default for Commands {
}
}

pub async fn run(mut app: App, subcommand: Commands) -> Result<()> {
pub async fn run(app: App, subcommand: Commands) -> Result<()> {
match subcommand {
Commands::Url(args) => url::run(app, args).await?,
Commands::Datapack(args) => datapack::run(app, args).await?,
Expand Down
6 changes: 5 additions & 1 deletion src/commands/import/mrpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ pub async fn run(mut app: App, args: Args) -> Result<()> {
std::fs::File::open(&src)?
} else {
let dl = if src.starts_with("http") && src.ends_with(".mrpack") {
Downloadable::Url { url: src, filename: None, desc: None }
Downloadable::Url {
url: src,
filename: None,
desc: None,
}
} else {
app.dl_from_string(&src).await?
};
Expand Down
2 changes: 1 addition & 1 deletion src/commands/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub fn initialize_environment() -> Result<()> {
);
}

if let Ok(Some(_)) = get_docker_version() {
if get_docker_version().is_ok() {
write_dockerfile(Path::new("."))?;
write_dockerignore(Path::new("."))?;
println!(
Expand Down
3 changes: 1 addition & 2 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ impl<'a> RunArgs {
}

pub async fn run(app: App, args: RunArgs) -> Result<()> {
let mut dev_session = args.create_dev_session(&app)?;

let dev_session = args.create_dev_session(&app)?;
dev_session.start().await?;

Ok(())
Expand Down
4 changes: 1 addition & 3 deletions src/commands/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use anyhow::Result;

use crate::app::App;

pub async fn run(mut app: App) -> Result<()> {


pub async fn run(_app: App) -> Result<()> {

Check warning on line 5 in src/commands/ws/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

function `run` is never used

warning: function `run` is never used --> src/commands/ws/mod.rs:5:14 | 5 | pub async fn run(_app: App) -> Result<()> { | ^^^ | = note: `#[warn(dead_code)]` on by default
Ok(())
}

Check warning on line 7 in src/commands/ws/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused `async` for function with no await statements

warning: unused `async` for function with no await statements --> src/commands/ws/mod.rs:5:1 | 5 | / pub async fn run(_app: App) -> Result<()> { 6 | | Ok(()) 7 | | } | |_^ | = help: consider removing the `async` from this function = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_async = note: `-W clippy::unused-async` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::unused_async)]`
14 changes: 10 additions & 4 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt::Debug, path::PathBuf, process::Child, time::Duration, collections::HashMap};
use std::{collections::HashMap, fmt::Debug, path::PathBuf, process::Child, time::Duration};

use anyhow::{Context, Result};
use console::style;
Expand All @@ -7,7 +7,7 @@ use tokio::io::AsyncWriteExt;

use crate::{
app::{AddonType, App, Resolvable, ResolvedFile},
model::{Lockfile, HookEvent},
model::{HookEvent, Lockfile},
};

pub mod addons;
Expand Down Expand Up @@ -57,7 +57,10 @@ impl<'a> BuildContext<'a> {
}

// hook: PreBuild
self.app.hooks().event(HookEvent::PreBuild, HashMap::default()).await?;
self.app
.hooks()
.event(HookEvent::PreBuild, HashMap::default())
.await?;

// actual stages contained here

Expand Down Expand Up @@ -103,7 +106,10 @@ impl<'a> BuildContext<'a> {
self.write_lockfile()?;

// hook: PostBuild
self.app.hooks().event(HookEvent::PostBuild, HashMap::default()).await?;
self.app
.hooks()
.event(HookEvent::PostBuild, HashMap::default())
.await?;

progress_bar.disable_steady_tick();
progress_bar.finish_and_clear();
Expand Down
10 changes: 6 additions & 4 deletions src/hot_reload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct DevSession<'a> {
pub test_mode: bool,
}

#[allow(clippy::enum_variant_names)]
pub enum Command {
Start,
EndSession,
Expand Down Expand Up @@ -119,7 +120,7 @@ impl<'a> DevSession<'a> {
async fn handle_commands(
mut self,
mut rx: mpsc::Receiver<Command>,
mut tx: mpsc::Sender<Command>,
tx: mpsc::Sender<Command>,
) -> Result<()> {
let mp = self.builder.app.multi_progress.clone();

Expand Down Expand Up @@ -220,7 +221,7 @@ impl<'a> DevSession<'a> {
}
},
Ok(Some(line)) = try_read_line(&mut stdout_lines) => {
let mut s = line.trim();
let s = line.trim();

if self.test_mode
&& !is_stopping
Expand Down Expand Up @@ -253,7 +254,7 @@ impl<'a> DevSession<'a> {
});
},
Ok(Some(line)) = stdin_lines.next_line() => {
let mut cmd = line.trim();
let cmd = line.trim();

self.builder.app.info(format!("Sending command: {cmd}"));
if let Some(ref mut stdin) = &mut child_stdin {
Expand All @@ -278,6 +279,7 @@ impl<'a> DevSession<'a> {
self.builder.app.info("Force-stopping development session...");
break 'l;
} else if !is_stopping {
is_session_ending = true;
self.builder.app.info("Stopping development session...");

tx.send(Command::SendCommand("stop\nend\n".to_owned())).await?;
Expand Down Expand Up @@ -507,7 +509,7 @@ impl<'a> DevSession<'a> {
)?)
}

pub async fn start(mut self) -> Result<()> {
pub async fn start(self) -> Result<()> {
let (tx, rx) = mpsc::channel(32);

if let Some(cfg_mutex) = self.hot_reload.clone() {
Expand Down
Loading

0 comments on commit db1d1c5

Please sign in to comment.