Removed unwrap calls, changed test serialization
This commit is contained in:
parent
8b7cade4e4
commit
b75adff1c8
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
/test_output.txt
|
/test_output.txt
|
||||||
|
/test_output.ron
|
76
Cargo.lock
generated
76
Cargo.lock
generated
@ -28,6 +28,21 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.21.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.11.1"
|
version = "3.11.1"
|
||||||
@ -171,7 +186,7 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"scratch",
|
"scratch",
|
||||||
"syn",
|
"syn 1.0.107",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -188,7 +203,7 @@ checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.107",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -333,7 +348,7 @@ checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "oxidefetch"
|
name = "oxidefetch"
|
||||||
version = "1.4.6"
|
version = "1.4.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byte-unit",
|
"byte-unit",
|
||||||
"chrono",
|
"chrono",
|
||||||
@ -341,24 +356,26 @@ dependencies = [
|
|||||||
"compound_duration",
|
"compound_duration",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"quoted-string",
|
"quoted-string",
|
||||||
|
"ron",
|
||||||
|
"serde",
|
||||||
"sysinfo",
|
"sysinfo",
|
||||||
"whoami",
|
"whoami",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.49"
|
version = "1.0.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
|
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.23"
|
version = "1.0.33"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
@ -391,6 +408,18 @@ dependencies = [
|
|||||||
"num_cpus",
|
"num_cpus",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ron"
|
||||||
|
version = "0.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"bitflags",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scopeguard"
|
name = "scopeguard"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@ -405,9 +434,23 @@ checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.152"
|
version = "1.0.192"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
|
checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.192"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.39",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
@ -420,6 +463,17 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.39"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sysinfo"
|
name = "sysinfo"
|
||||||
version = "0.29.10"
|
version = "0.29.10"
|
||||||
@ -500,7 +554,7 @@ dependencies = [
|
|||||||
"once_cell",
|
"once_cell",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.107",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -522,7 +576,7 @@ checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.107",
|
||||||
"wasm-bindgen-backend",
|
"wasm-bindgen-backend",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
18
Cargo.toml
18
Cargo.toml
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "oxidefetch"
|
name = "oxidefetch"
|
||||||
description = "A fast, cross platform Fetch program for your terminal"
|
description = "A fast, cross platform Fetch program for your terminal"
|
||||||
version = "1.4.6"
|
version = "1.4.7"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = [ "NamedNeon", "shibedrill" ]
|
authors = [ "NamedNeon", "shibedrill" ]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@ -16,9 +16,14 @@ colored = "2.0.0"
|
|||||||
compound_duration = "1.2.0"
|
compound_duration = "1.2.0"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
quoted-string = "0.6.1"
|
quoted-string = "0.6.1"
|
||||||
|
ron = "0.8.1"
|
||||||
sysinfo = "0.29.1"
|
sysinfo = "0.29.1"
|
||||||
whoami = "1.3.0"
|
whoami = "1.3.0"
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
version = "1.0.192"
|
||||||
|
features = ["derive"]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true
|
strip = true
|
||||||
opt-level = "z"
|
opt-level = "z"
|
||||||
@ -27,13 +32,4 @@ codegen-units = 1
|
|||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
field-titles = []
|
field-titles = []
|
||||||
|
|
||||||
[package.metadata.rpm]
|
|
||||||
package = "oxidefetch"
|
|
||||||
|
|
||||||
[package.metadata.rpm.cargo]
|
|
||||||
buildflags = ["--release"]
|
|
||||||
|
|
||||||
[package.metadata.rpm.targets]
|
|
||||||
oxidefetch = { path = "/usr/bin/oxidefetch" }
|
|
@ -98,6 +98,7 @@ No weird quirks to report at this time.
|
|||||||
**1.4.4:** Fixed an issue where GPUs would all print on one line.
|
**1.4.4:** Fixed an issue where GPUs would all print on one line.
|
||||||
**1.4.5:** Minor changes to system color detection. Removed all warnings.
|
**1.4.5:** Minor changes to system color detection. Removed all warnings.
|
||||||
**1.4.6:** Cargo formatting applied to all files. Mild string reformatting in print statements.
|
**1.4.6:** Cargo formatting applied to all files. Mild string reformatting in print statements.
|
||||||
|
**1.4.7:** Removed several `unwrap()` calls. Changed debug output to serialize to RON.
|
||||||
|
|
||||||
### License
|
### License
|
||||||
This software is covered by the MIT license. See license.txt for details.
|
This software is covered by the MIT license. See license.txt for details.
|
||||||
|
25
src/main.rs
25
src/main.rs
@ -33,6 +33,9 @@ use std::env;
|
|||||||
use sysinfo::*;
|
use sysinfo::*;
|
||||||
use whoami;
|
use whoami;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Generate system info struct
|
// Generate system info struct
|
||||||
let sys_info = Information::new();
|
let sys_info = Information::new();
|
||||||
@ -63,9 +66,8 @@ fn main() {
|
|||||||
color_print("Terminal:\t", '', &sys_info.terminal, "magenta");
|
color_print("Terminal:\t", '', &sys_info.terminal, "magenta");
|
||||||
color_print("CPU:\t", '', &Some(sys_info.cpu), "green");
|
color_print("CPU:\t", '', &Some(sys_info.cpu), "green");
|
||||||
|
|
||||||
if sys_info.gpu.is_some() {
|
if let Some(gpuvec) = sys_info.gpu {
|
||||||
let gpus = sys_info.gpu.unwrap();
|
for gpu in gpuvec {
|
||||||
for gpu in gpus {
|
|
||||||
color_print("GPU:\t", '', &Some(gpu), "bright green")
|
color_print("GPU:\t", '', &Some(gpu), "bright green")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,17 +78,18 @@ fn main() {
|
|||||||
#[allow(unused_variables)] // The field title var is sometimes unused due to compile time features
|
#[allow(unused_variables)] // The field title var is sometimes unused due to compile time features
|
||||||
fn color_print(field_title: &str, icon: char, field: &Option<String>, color: &str) {
|
fn color_print(field_title: &str, icon: char, field: &Option<String>, color: &str) {
|
||||||
// If the field is missing, it won't print.
|
// If the field is missing, it won't print.
|
||||||
if field.is_some() {
|
if let Some(fieldvalue) = field {
|
||||||
#[cfg(feature = "field-titles")]
|
#[cfg(feature = "field-titles")]
|
||||||
print!("{} ", field_title.bright_white());
|
print!("{} ", field_title.bright_white());
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
format!("{} {}", icon, field.as_ref().unwrap()).color(color)
|
format!("{} {}", icon, fieldvalue).color(color)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[cfg_attr(test, derive(Serialize))]
|
||||||
struct Information {
|
struct Information {
|
||||||
// Only fields whose setters can fail, are given Option<String> types.
|
// Only fields whose setters can fail, are given Option<String> types.
|
||||||
// Unsure if I should coerce these fields into an Option<String> *here*, or
|
// Unsure if I should coerce these fields into an Option<String> *here*, or
|
||||||
@ -137,8 +140,8 @@ impl Information {
|
|||||||
// Tracks the SHELL env var and trims the last item from the resultant fs path.
|
// Tracks the SHELL env var and trims the last item from the resultant fs path.
|
||||||
shell: {
|
shell: {
|
||||||
let var = env::var("SHELL");
|
let var = env::var("SHELL");
|
||||||
if var.is_ok() {
|
if let Ok(var_ok) = var {
|
||||||
Some(format!("{}", var.unwrap().split('/').last().unwrap()))
|
Some(format!("{}", var_ok.split('/').last().unwrap()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -288,14 +291,16 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn log_gathered_data() {
|
pub fn log_gathered_data() {
|
||||||
let sys_info = Information::new();
|
let sys_info = Information::new();
|
||||||
let data_string = format!("{:#?}", sys_info);
|
//let data_string = format!("{:#?}", sys_info);
|
||||||
let result = fs::write("./test_output.txt", data_string);
|
let data_string = ron::ser::to_string_pretty(&sys_info, ron::ser::PrettyConfig::default())
|
||||||
|
.expect("Failed to serialize data structure. Aborting...");
|
||||||
|
let result = fs::write("./test_output.ron", data_string);
|
||||||
|
|
||||||
if result.is_ok() {
|
if result.is_ok() {
|
||||||
println!(
|
println!(
|
||||||
"
|
"
|
||||||
HEY THERE! A logging file was generated by this test. \
|
HEY THERE! A logging file was generated by this test. \
|
||||||
It's located in this folder, and called 'test_output.txt'. \
|
It's located in this folder, and called 'test_output.ron'. \
|
||||||
SEND THIS FILE to the maintainer of the project!
|
SEND THIS FILE to the maintainer of the project!
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user