summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-11-16 23:15:20 +0300
committerNamilskyy <alive6863@gmail.com>2025-11-17 20:50:22 +0300
commite480ef5a1af5daec4fbc1ae7b3e81cba0c340c5e (patch)
tree9b6e07a581b40202e71c9ac6600b451426422283
parent9ad90109b19de4ae888f71310b9b81db98c2f02f (diff)
Some fixed
-rw-r--r--src/main.rs164
1 files changed, 44 insertions, 120 deletions
diff --git a/src/main.rs b/src/main.rs
index 4288a70..545ae65 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -29,137 +29,61 @@ SOFTWARE.
*/
-use std::fs;
-use std::path::PathBuf;
+use std::os::linux::process;
-use clap::{Parser, Subcommand};
-use termimage::Options;
+use clap::{Cli, Command, Subcommand};
+use termimage;
mod parser;
-mod shared;
-
-use parser::{get_config, parse_weather, Config};
-use shared::WeatherData;
-
-#[derive(Parser)]
-#[command(name = "wfetch")]
-#[command(about = "Weather fetch tool")]
-struct Cli {
- #[command(subcommand)]
- command: Option<Commands>,
-}
+use parser::{get_config, Config};
+// use crate::configmanager::{Config, handle_config};
#[derive(Subcommand)]
enum Commands {
- Config,
- Fetch,
- Clean,
- Help,
- Today,
- Tomorrow,
- RebuildCache,
+ Config,
+ Fetch,
+ Clean,
+ Help,
+ Today,
+ Tomorrow,
+ RebuildCache
}
+fn process_config() -> Result<Config, Box<dyn std::error::Error>> {
+ let cfg: Config = get_config().unwrap();
-fn process_config() -> Result<(), Box<dyn std::error::Error>> {
- let _cfg: Config = get_config()?;
- println!("Config is valid");
- Ok(())
+ Ok(cfg);
}
-fn parse_cached() -> Result<WeatherData, Box<dyn std::error::Error>> {
- let home = std::env::var("HOME")?;
- let cache_path = format!("{}/.cache/WeatherFetch/weather.json", home);
-
- if !PathBuf::from(&cache_path).exists() {
- return Err("Cache file not found".into());
- }
-
- let cache_data = fs::read_to_string(&cache_path)?;
- let weather_data: WeatherData = serde_json::from_str(&cache_data)?;
- Ok(weather_data)
-}
+fn main() -> Result<(), Box<dyn std::error::Error>> {
-fn print_help() -> Result<(), Box<dyn std::error::Error>> {
- println!("Help command");
- println!("Usage: wfetch <command>");
- println!("Commands:");
- println!(" config - Check config");
- println!(" fetch - Fetch weather-data");
- println!(" clean - Clean cache");
- println!(" help - Print help");
- println!(" today - Print today weather");
- println!(" tomorrow - Print tomorrow weather");
- println!(" rebuild-cache - Rebuild cache");
- Ok(())
-}
+ let config = process_config()?;
+ let cli: Cli = Cli::parse();
-fn clean_cache() -> Result<(), Box<dyn std::error::Error>> {
- let home = std::env::var("HOME")?;
- let cache_path = format!("{}/.cache/WeatherFetch/weather.json", home);
- if PathBuf::from(&cache_path).exists() {
- fs::remove_file(&cache_path)?;
- println!("Cache cleaned successfully");
- } else {
- println!("Cache file not found");
- }
- Ok(())
-}
+ match cli.command {
+ Commands::Config => {
+ println!("Testing config."); // Заглушкии
+ // let test_result: bool = handle_config(config);
+ }
+ Commands::Fetch => {
+ println!("Fetching weather data.");
+
+ }
+ Commands::Clean => {
+ println!("Clean");
+ }
+ Commands::Help => {
+ println!("Help");
+ }
+ Commands::Today => {
+ println!("Today");
+ }
+ Commands::Tomorrow => {
+ println!("Tomorrow");
+ }
+ Commands::RebuildCache => {
+ }
+ }
+
+ }
-fn rebuild_cache() -> Result<(), Box<dyn std::error::Error>> {
- let rt = tokio::runtime::Runtime::new()?;
- let weather_data = rt.block_on(parse_weather())?;
-
- let home = std::env::var("HOME")?;
- let cache_dir = format!("{}/.cache/WeatherFetch", home);
- fs::create_dir_all(&cache_dir)?;
-
- let cache_path = format!("{}/weather.json", cache_dir);
- let json_data = serde_json::to_string_pretty(&weather_data)?;
- fs::write(&cache_path, json_data)?;
-
- println!("Cache rebuilt successfully");
- Ok(())
-}
-fn main() -> Result<(), Box<dyn std::error::Error>> {
- let cli = Cli::parse();
-
- match cli.command {
- Some(Commands::Config) => {
- println!("Config checker command");
- process_config()?;
- Ok(())
- },
- Some(Commands::Fetch) => {
- println!("Fetch weather-data command");
- let rt = tokio::runtime::Runtime::new()?;
- let weather_data = rt.block_on(parse_weather())?;
- println!("Weather data fetched: {:?}", weather_data);
- Ok(())
- },
- Some(Commands::Clean) => {
- println!("Clean cache command");
- clean_cache()?;
- Ok(())
- },
- Some(Commands::Help) => {
- print_help()
- },
- Some(Commands::Today) => {
- println!("Today weather command");
- Ok(())
- },
- Some(Commands::Tomorrow) => {
- println!("Tomorrow weather command");
- Ok(())
- },
- Some(Commands::RebuildCache) => {
- println!("Rebuild cache command");
- rebuild_cache()?;
- Ok(())
- },
- None => {
- print_help()
- },
- }
-} \ No newline at end of file