Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

use standard locations for config file

+31 -5
+7
Cargo.lock
··· 815 815 "strum", 816 816 "tokio", 817 817 "toml", 818 + "xdg", 818 819 ] 819 820 820 821 [[package]] ··· 1314 1315 "cfg-if", 1315 1316 "windows-sys 0.48.0", 1316 1317 ] 1318 + 1319 + [[package]] 1320 + name = "xdg" 1321 + version = "2.5.2" 1322 + source = "registry+https://github.com/rust-lang/crates.io-index" 1323 + checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
+1
cli/Cargo.toml
··· 13 13 strum = { version = "0.26", features = ["derive"] } 14 14 tokio = { version = "1", features = ["full"] } 15 15 toml = "0.8.12" 16 + xdg = "2.5.2"
+23 -5
cli/src/main.rs
··· 4 4 use clap::Subcommand; 5 5 use serde::Deserialize; 6 6 use std::fs; 7 + use std::path::{Path, PathBuf}; 8 + use xdg; 7 9 8 10 mod sower; 9 11 ··· 14 16 action: Actions, 15 17 16 18 #[arg(long, short, global = true)] 17 - config: Option<String>, 19 + config: Option<PathBuf>, 18 20 19 21 #[arg(long, short, global = true)] 20 22 name: Option<String>, ··· 124 126 async fn main() -> Result<(), Box<dyn std::error::Error>> { 125 127 let cli = Cli::parse(); 126 128 127 - let config: Config = match cli.config { 128 - Some(path) => { 129 - let config_string = fs::read_to_string(path)?; 129 + let config_file = match cli.config { 130 + Some(path) => path, 131 + None => match std::env::var("USER") { 132 + Ok(user) => match user.as_ref() { 133 + "root" => PathBuf::from("/etc/sower/config.toml"), 134 + _ => xdg::BaseDirectories::with_prefix("sower") 135 + .expect("cannot locate XDG directories") 136 + .get_config_file("config.toml"), 137 + }, 138 + Err(_) => PathBuf::from("/etc/sower/config.toml"), 139 + }, 140 + }; 141 + 142 + dbg!(&config_file); 143 + 144 + let config = match Path::try_exists(&config_file) { 145 + Ok(true) => { 146 + let config_string = fs::read_to_string(config_file)?; 130 147 toml::from_str(&config_string).expect("failed to parse config file") 131 148 } 132 - None => Config { 149 + _ => Config { 133 150 name: None, 134 151 seed_type: None, 135 152 url: None, 136 153 }, 137 154 }; 138 155 156 + // cli overrides config 139 157 let config = config.name(cli.name).seed_type(cli.seed_type).url(cli.url); 140 158 141 159 let tree = Tree::new(&config).await?;