Skip to content

Commit

Permalink
chore: add dependency to maestro-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
llenotre committed Nov 10, 2024
1 parent 7a2b417 commit 6f74df1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 37 deletions.
51 changes: 50 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.87"
common = { path = "../common" }
tokio = { version = "1.40.0", features = ["macros", "rt", "rt-multi-thread"] }
tokio = { version = "1.41.1", features = ["macros", "rt", "rt-multi-thread"] }
utils = { git = "https://github.com/maestro-os/maestro-utils" }

[features]
default = []
Expand Down
8 changes: 3 additions & 5 deletions client/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This module handles package installation.

use crate::confirm;
use anyhow::bail;
use anyhow::Result;
use common::anyhow::bail;
use common::anyhow::Result;
use common::package::Package;
use common::repository;
use common::repository::Repository;
Expand Down Expand Up @@ -123,9 +123,7 @@ pub async fn install(
}
}

print!("Total download size: ");
common::util::print_size(total_size);
println!();
println!("Total download size: {}", ByteSize(total_size));
}
#[cfg(not(feature = "network"))]
{
Expand Down
4 changes: 2 additions & 2 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ mod remove;
#[cfg(feature = "network")]
mod update;

use anyhow::anyhow;
use anyhow::Result;
use common::anyhow::anyhow;
use common::anyhow::Result;
use common::Environment;
use install::install;
use remove::remove;
Expand Down
5 changes: 2 additions & 3 deletions client/src/remove.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! TODO doc

use anyhow::anyhow;
use anyhow::bail;
use anyhow::Result;
use common::anyhow::Result;
use common::anyhow::{anyhow, bail};
use common::package;
use common::Environment;

Expand Down
2 changes: 2 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub mod repository;
pub mod util;
pub mod version;

pub use anyhow;

#[cfg(feature = "network")]
pub mod download;

Expand Down
24 changes: 0 additions & 24 deletions common/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,6 @@ pub fn recursive_copy(src: &Path, dst: &Path) -> io::Result<()> {
Ok(())
}

// TODO delete (reuse the version in maestro-utils)
/// Prints the given size in bytes into a human-readable form.
pub fn print_size(mut size: u64) {
let mut level = 0;
while level < 6 && size > 1024 {
size /= 1024;
level += 1;
}

let suffix = match level {
0 => "bytes",
1 => "KiB",
2 => "MiB",
3 => "GiB",
4 => "TiB",
5 => "PiB",
6 => "EiB",

_ => return,
};

print!("{size} {suffix}");
}

// TODO: rework to allow deserialize from structs with lifetimes (currently unefficient)
/// Reads a JSON file.
pub fn read_json<T: for<'a> Deserialize<'a>>(file: &Path) -> io::Result<T> {
Expand Down

0 comments on commit 6f74df1

Please sign in to comment.