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
|
||||
/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"
|
||||
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]]
|
||||
name = "bumpalo"
|
||||
version = "3.11.1"
|
||||
@ -171,7 +186,7 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"scratch",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -188,7 +203,7 @@ checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -333,7 +348,7 @@ checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
|
||||
|
||||
[[package]]
|
||||
name = "oxidefetch"
|
||||
version = "1.4.6"
|
||||
version = "1.4.7"
|
||||
dependencies = [
|
||||
"byte-unit",
|
||||
"chrono",
|
||||
@ -341,24 +356,26 @@ dependencies = [
|
||||
"compound_duration",
|
||||
"lazy_static",
|
||||
"quoted-string",
|
||||
"ron",
|
||||
"serde",
|
||||
"sysinfo",
|
||||
"whoami",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.49"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
|
||||
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.23"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@ -391,6 +408,18 @@ dependencies = [
|
||||
"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]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
@ -405,9 +434,23 @@ checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.152"
|
||||
version = "1.0.192"
|
||||
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]]
|
||||
name = "syn"
|
||||
@ -420,6 +463,17 @@ dependencies = [
|
||||
"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]]
|
||||
name = "sysinfo"
|
||||
version = "0.29.10"
|
||||
@ -500,7 +554,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
@ -522,7 +576,7 @@ checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.107",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
18
Cargo.toml
18
Cargo.toml
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "oxidefetch"
|
||||
description = "A fast, cross platform Fetch program for your terminal"
|
||||
version = "1.4.6"
|
||||
version = "1.4.7"
|
||||
edition = "2021"
|
||||
authors = [ "NamedNeon", "shibedrill" ]
|
||||
license = "MIT"
|
||||
@ -16,9 +16,14 @@ colored = "2.0.0"
|
||||
compound_duration = "1.2.0"
|
||||
lazy_static = "1.4.0"
|
||||
quoted-string = "0.6.1"
|
||||
ron = "0.8.1"
|
||||
sysinfo = "0.29.1"
|
||||
whoami = "1.3.0"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0.192"
|
||||
features = ["derive"]
|
||||
|
||||
[profile.release]
|
||||
strip = true
|
||||
opt-level = "z"
|
||||
@ -27,13 +32,4 @@ codegen-units = 1
|
||||
panic = "abort"
|
||||
|
||||
[features]
|
||||
field-titles = []
|
||||
|
||||
[package.metadata.rpm]
|
||||
package = "oxidefetch"
|
||||
|
||||
[package.metadata.rpm.cargo]
|
||||
buildflags = ["--release"]
|
||||
|
||||
[package.metadata.rpm.targets]
|
||||
oxidefetch = { path = "/usr/bin/oxidefetch" }
|
||||
field-titles = []
|
@ -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.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.7:** Removed several `unwrap()` calls. Changed debug output to serialize to RON.
|
||||
|
||||
### License
|
||||
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 whoami;
|
||||
|
||||
#[cfg(test)]
|
||||
use serde::Serialize;
|
||||
|
||||
fn main() {
|
||||
// Generate system info struct
|
||||
let sys_info = Information::new();
|
||||
@ -63,9 +66,8 @@ fn main() {
|
||||
color_print("Terminal:\t", '', &sys_info.terminal, "magenta");
|
||||
color_print("CPU:\t", '', &Some(sys_info.cpu), "green");
|
||||
|
||||
if sys_info.gpu.is_some() {
|
||||
let gpus = sys_info.gpu.unwrap();
|
||||
for gpu in gpus {
|
||||
if let Some(gpuvec) = sys_info.gpu {
|
||||
for gpu in gpuvec {
|
||||
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
|
||||
fn color_print(field_title: &str, icon: char, field: &Option<String>, color: &str) {
|
||||
// If the field is missing, it won't print.
|
||||
if field.is_some() {
|
||||
if let Some(fieldvalue) = field {
|
||||
#[cfg(feature = "field-titles")]
|
||||
print!("{} ", field_title.bright_white());
|
||||
println!(
|
||||
"{}",
|
||||
format!("{} {}", icon, field.as_ref().unwrap()).color(color)
|
||||
format!("{} {}", icon, fieldvalue).color(color)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(test, derive(Serialize))]
|
||||
struct Information {
|
||||
// Only fields whose setters can fail, are given Option<String> types.
|
||||
// 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.
|
||||
shell: {
|
||||
let var = env::var("SHELL");
|
||||
if var.is_ok() {
|
||||
Some(format!("{}", var.unwrap().split('/').last().unwrap()))
|
||||
if let Ok(var_ok) = var {
|
||||
Some(format!("{}", var_ok.split('/').last().unwrap()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -288,14 +291,16 @@ mod test {
|
||||
#[test]
|
||||
pub fn log_gathered_data() {
|
||||
let sys_info = Information::new();
|
||||
let data_string = format!("{:#?}", sys_info);
|
||||
let result = fs::write("./test_output.txt", data_string);
|
||||
//let data_string = format!("{:#?}", sys_info);
|
||||
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() {
|
||||
println!(
|
||||
"
|
||||
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!
|
||||
"
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user