summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authornamilsk <namilsk@namilsk.tech>2026-02-12 15:52:08 +0300
committernamilsk <namilsk@namilsk.tech>2026-02-12 15:52:08 +0300
commitd7af285e6293d265998612cd409d5d335bf92d6b (patch)
treebaa4f3def4bc581ad48e10fd45ec7622059b2891 /src/main.rs
parent5ffc100655e8773e512342fa58f24548560dca51 (diff)
Implemented `get-arts` subcommand for automatic downloading arts.yamlmain
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 46334a2..8391144 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -68,7 +68,8 @@ enum Commands {
RebuildCache,
CheckCfg,
Credits,
- DebugOutput
+ DebugOutput,
+ GetArts
}
/// Micro config-validator, easily you can just `wfetch fetch` and see the error
@@ -295,10 +296,38 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("ASCII arts by www.asciiart.eu: Joan G. Stark");
Ok(())
}
+ Some(Commands::GetArts) => {
+ println!("Fetching arts.yaml for you.");
+
+ // Create the config directory if it doesn't exist
+ let config_dir = format!("{}/.config/WeatherFetch", std::env::var("HOME")?);
+ std::fs::create_dir_all(&config_dir)?;
+
+ let rt = tokio::runtime::Runtime::new()?;
+ let result: Result<(), Box<dyn std::error::Error>> = rt.block_on(async {
+ let client = reqwest::Client::new();
+ let url = "https://raw.githubusercontent.com/Nam4ik/WeatherFetch/refs/heads/main/src/arts.yaml";
+ let response = client.get(url).send().await?;
+
+ if response.status().is_success() {
+ let arts_yaml_content = response.text().await?;
+ let arts_yaml_path = format!("{}/arts.yaml", config_dir);
+
+ std::fs::write(&arts_yaml_path, arts_yaml_content)?;
+ println!("arts.yaml successfully downloaded to: {}", arts_yaml_path);
+ Ok(())
+ } else {
+ Err(format!("Failed to download arts.yaml. Status: {}", response.status()).into())
+ }
+ });
+ result
+ }
+
None => {
println!("No subcommand specified.");
println!("Run `wfetch -h` or `wfetch help`");
println!("to see help message.");
+ println!("Run `wfetch get-arts` if you havent arts.yaml");
Ok(())
}
}