diff --git a/Cargo.lock b/Cargo.lock index e264ea0..8f7ad5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,12 +118,34 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "indexmap" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -158,6 +180,8 @@ version = "0.9.1" dependencies = [ "clap", "color-print", + "serde", + "toml", ] [[package]] @@ -178,6 +202,35 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "serde" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + [[package]] name = "strsim" version = "0.11.1" @@ -195,6 +248,40 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "unicode-ident" version = "1.0.14" @@ -279,3 +366,12 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6f5bb5257f2407a5425c6e749bfd9692192a73e70a6060516ac04f889087d68" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml index db96394..4ff39e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,5 @@ edition = "2021" [dependencies] clap = { version = "4.5.18", features = ["cargo", "derive"] } color-print = "0.3.5" +serde = "1.0.217" +toml = "0.8.19" diff --git a/config.template b/config.template new file mode 100644 index 0000000..9d9693d --- /dev/null +++ b/config.template @@ -0,0 +1,17 @@ +[PackageManagers] +apt = n +dnf = y +pacman = n +python = n +urpmi = n +zypper = n + +[Firmware] +firmware = y + +[Containers] +distrobox = y +flatpak = y +podman = y +snap = n + diff --git a/src/main.rs b/src/main.rs index a0b2e31..9400462 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,12 @@ use std::path::{Path}; use color_print::{cprintln}; use clap::{command, Arg, ArgAction}; +//use std::fs::File; +//use std::io::Write; +//use serde::Serialize; +//use toml::to_string; + + const VERSION: &'static str = "0.9.1"; fn trim_newline(s: &mut String) { @@ -14,6 +20,35 @@ fn trim_newline(s: &mut String) { } } +/*fn toml_create_default () { + #[derive(Serialize)] + struct toml_data { + config: PackageManagers, + config: Firmware, + config: Containers, + } + + struct PackageMangers { + apt: bool, + dnf: bool, + pacman: bool, + python: bool, + urppmi: bool, + zypper: bool, + } + + struct Firmware { + firmware: bool + } + + struct Containers { + distrobox: bool, + flatpak: bool, + podman: bool, + snap: bool, + } +}*/ + fn update_apt() { let find_sudo = Command::new("which") .arg("sudo").stdout(Stdio::piped()).output().unwrap(); @@ -368,6 +403,19 @@ fn main() { // Clear terminal, and move cursor to 1,1 inside the terminal // print!("{esc}[2J{esc}[1;1H", esc = 27 as char); + // Check for default ini file's existence and + // create new one if file does not exist + let toml_exists = Path::new("~/.config/osupdater.toml").exists(); + if toml_exists == false { + println!("No config file found"); + println!("Creating new config at : ~/.config/osupdater.toml"); + //toml_create_default (); + } else if toml_exists == true { + println!("Config file found at ~/.config/osupater.toml"); + } + + // Parse ini + // Find sudo let find_sudo = Command::new("which") .arg("sudo").stdout(Stdio::piped()).output().unwrap();