lib/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use clap::Parser;
use cli::{Cli, Command, Destinations};

mod cli;
mod commands;
mod config;
mod destinations;

pub async fn run() -> Result<(), String> {
    let cli = Cli::parse();

    match cli.cmd {
        Command::Load => match config::configure() {
            Ok(_) => {
                println!(
                    "The configuration file has been created here: \"{}\". \nTo start using Musket, please fill in the configuration file with your data.",
                    config::get_configuration_path()
                        .unwrap_or_default()
                        .to_string_lossy()
                );
            }
            Err(e) => {
                return Err(format!(
                    "The configuration file cannot be created due to \"{}\".",
                    e
                ));
            }
        },
        Command::Fire {
            url,
            destination,
            tags,
        } => {
            if destination.is_none() {
                return Err(format!("The url \"{}\" cannot be sent to a non-existing destination. Set, at least, one valid destination.", url));
            }

            let cfg = config::configure().map_err(|err| format!("{}.", err))?;

            let vector_of_tags = tags.unwrap_or_default();
            let destinations = destination.unwrap_or_default();

            for target in destinations {
                match target {
                    Destinations::All => {
                        commands::turso::execute(&cfg, &url, &vector_of_tags).await?;
                        commands::linkedin::execute(&cfg, &url, &vector_of_tags).await?;
                    }
                    Destinations::Turso => {
                        commands::turso::execute(&cfg, &url, &vector_of_tags).await?;
                    }
                    Destinations::LinkedIn => {
                        commands::linkedin::execute(&cfg, &url, &vector_of_tags).await?;
                    }
                }
            }
        }
    }
    Ok(())
}