From 109227b74c7950aac73e396618f34b8992ffc200 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Thu, 26 Sep 2024 18:01:55 -0700 Subject: [PATCH] feat(bar): add quickstart flag, remove yaml format This commit adds a --quickstart flag to the komorebi-bar binary to output an example komorebi.bar.json into the user's desired configuration directory. This is to avoid the case where running komorebic quickstart would result in clobbering an existing komorebi.json file. Additionally, if a user tries to run the bar for the first time without a configuration file, the example configuration will be written to disk for them. Finally support for loading a komorebi.bar.yaml file has been removed because I have no desire to support multiple configuration formats over the long term. --- Cargo.lock | 68 +++++++------------------------------- komorebi-bar/Cargo.toml | 1 - komorebi-bar/src/config.rs | 1 - komorebi-bar/src/main.rs | 45 +++++++++++++++++-------- 4 files changed, 43 insertions(+), 72 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87ac0c9b..a934cdd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2164,7 +2164,7 @@ checksum = "9c08c1f623a8d0b722b8b99f821eb0ba672a1618f0d3b16ddbee1cedd2dd8557" dependencies = [ "bitflags 2.6.0", "gpu-descriptor-types", - "hashbrown 0.14.5", + "hashbrown", ] [[package]] @@ -2188,7 +2188,7 @@ dependencies = [ "futures-core", "futures-sink", "http", - "indexmap 2.5.0", + "indexmap", "slab", "tokio", "tokio-util", @@ -2205,12 +2205,6 @@ dependencies = [ "crunchy", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.14.5" @@ -2498,16 +2492,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - [[package]] name = "indexmap" version = "2.5.0" @@ -2515,7 +2499,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown", ] [[package]] @@ -2698,7 +2682,7 @@ dependencies = [ "schemars", "serde", "serde_json_lenient", - "serde_yaml 0.9.34+deprecated", + "serde_yaml", "shadow-rs", "strum", "sysinfo", @@ -2741,7 +2725,6 @@ dependencies = [ "schemars", "serde", "serde_json_lenient", - "serde_yaml 0.8.26", "starship-battery", "sysinfo", "tracing", @@ -2802,7 +2785,7 @@ dependencies = [ "schemars", "serde", "serde_json_lenient", - "serde_yaml 0.9.34+deprecated", + "serde_yaml", "shadow-rs", "sysinfo", "thiserror", @@ -2937,12 +2920,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -3192,7 +3169,7 @@ dependencies = [ "bitflags 2.6.0", "codespan-reporting", "hexf-parse", - "indexmap 2.5.0", + "indexmap", "log", "num-traits", "rustc-hash", @@ -3881,7 +3858,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.5.0", + "indexmap", ] [[package]] @@ -3920,7 +3897,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016" dependencies = [ "base64", - "indexmap 2.5.0", + "indexmap", "quick-xml 0.32.0", "serde", "time", @@ -4656,25 +4633,13 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_yaml" -version = "0.8.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" -dependencies = [ - "indexmap 1.9.3", - "ryu", - "serde", - "yaml-rust", -] - [[package]] name = "serde_yaml" version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.5.0", + "indexmap", "itoa", "ryu", "serde", @@ -5316,7 +5281,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.5.0", + "indexmap", "toml_datetime", "winnow 0.5.40", ] @@ -5327,7 +5292,7 @@ version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap 2.5.0", + "indexmap", "serde", "serde_spanned", "toml_datetime", @@ -5931,7 +5896,7 @@ dependencies = [ "cfg_aliases 0.1.1", "codespan-reporting", "document-features", - "indexmap 2.5.0", + "indexmap", "log", "naga", "once_cell", @@ -6627,15 +6592,6 @@ version = "0.8.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af4e2e2f7cba5a093896c1e150fbfe177d1883e7448200efb81d40b9d339ef26" -[[package]] -name = "yaml-rust" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] - [[package]] name = "zbus" version = "3.15.2" diff --git a/komorebi-bar/Cargo.toml b/komorebi-bar/Cargo.toml index 79dcac8b..b4a8ba66 100644 --- a/komorebi-bar/Cargo.toml +++ b/komorebi-bar/Cargo.toml @@ -27,7 +27,6 @@ num-traits = "0.2.19" schemars = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } -serde_yaml = "0.8" starship-battery = "0.10" sysinfo = { workspace = true } tracing = { workspace = true } diff --git a/komorebi-bar/src/config.rs b/komorebi-bar/src/config.rs index 255edfc8..20d11a06 100644 --- a/komorebi-bar/src/config.rs +++ b/komorebi-bar/src/config.rs @@ -57,7 +57,6 @@ impl KomobarConfig { pub fn read(path: &PathBuf) -> color_eyre::Result { let content = std::fs::read_to_string(path)?; let mut value: Self = match path.extension().unwrap().to_string_lossy().as_str() { - "yaml" => serde_yaml::from_str(&content)?, "json" => serde_json::from_str(&content)?, _ => panic!("unsupported format"), }; diff --git a/komorebi-bar/src/main.rs b/komorebi-bar/src/main.rs index fea08029..a93a2837 100644 --- a/komorebi-bar/src/main.rs +++ b/komorebi-bar/src/main.rs @@ -15,7 +15,6 @@ use crate::bar::Komobar; use crate::config::KomobarConfig; use crate::config::Position; use clap::Parser; -use color_eyre::eyre::OptionExt; use eframe::egui::ViewportBuilder; use font_loader::system_fonts; use hotwatch::EventKind; @@ -45,6 +44,9 @@ struct Opts { /// Path to a JSON or YAML configuration file #[clap(short, long)] config: Option, + /// Write an example komorebi.bar.json to disk + #[clap(long)] + quickstart: bool, } fn main() -> color_eyre::Result<()> { @@ -102,28 +104,43 @@ fn main() -> color_eyre::Result<()> { }, ); + if opts.quickstart { + let komorebi_bar_json = include_str!("../../docs/komorebi.bar.example.json").to_string(); + std::fs::write(home_dir.join("komorebi.bar.json"), komorebi_bar_json)?; + println!( + "Example komorebi.bar.json file written to {}", + home_dir.as_path().display() + ); + + std::process::exit(0); + } + + let default_config_path = home_dir.join("komorebi.bar.json"); + let config_path = opts.config.map_or_else( || { - let mut config = home_dir.join("komorebi.bar.json"); - if !config.is_file() { - config.pop(); - config.push("komorebi.bar.yaml"); - } - - if !config.is_file() { + if !default_config_path.is_file() { None } else { - Some(config) + Some(default_config_path.clone()) } }, Option::from, ); let config = match config_path { - None => panic!( - "no komorebi.bar.json or komorebi.bar.yaml found in {}", - home_dir.as_path().to_string_lossy() - ), + None => { + let komorebi_bar_json = + include_str!("../../docs/komorebi.bar.example.json").to_string(); + + std::fs::write(&default_config_path, komorebi_bar_json)?; + tracing::info!( + "created example configuration file: {}", + default_config_path.as_path().display() + ); + + KomobarConfig::read(&default_config_path)? + } Some(ref config) => { tracing::info!( "found configuration file: {}", @@ -134,7 +151,7 @@ fn main() -> color_eyre::Result<()> { } }; - let config_path = config_path.ok_or_eyre("config path not found")?; + let config_path = config_path.unwrap_or(default_config_path); let state = serde_json::from_str::(&komorebi_client::send_query( &SocketMessage::State,