Skip to main content

dev_scripts/
main.rs

1//! The `dev-scripts` CLI tool.
2
3use std::process::ExitCode;
4
5use clap::Parser;
6use cli::Cli;
7use simplelog::{Config, SimpleLogger};
8
9use crate::{
10    cache::CacheDir,
11    cli::Command,
12    commands::{clean_files, compare_source_info, download_files, test_files},
13    error::Error,
14};
15
16mod cache;
17mod cli;
18mod cmd;
19mod commands;
20mod consts;
21mod error;
22pub mod sync;
23pub mod testing;
24mod ui;
25
26/// Runs a command of the `dev-scripts` executable.
27fn run_command() -> Result<(), Error> {
28    let cli = Cli::parse();
29    SimpleLogger::init(cli.verbose.log_level_filter(), Config::default())?;
30
31    let cache_dir = if let Some(path) = cli.cache_dir {
32        CacheDir::from(path)
33    } else {
34        CacheDir::from_xdg()?
35    };
36
37    match cli.cmd {
38        Command::CompareSrcinfo {
39            pkgbuild_path,
40            srcinfo_path,
41        } => compare_source_info(pkgbuild_path, srcinfo_path),
42        Command::TestFormat {
43            repositories,
44            file_type,
45        } => test_files(cache_dir, file_type, repositories),
46        Command::Download {
47            repositories,
48            source,
49        } => download_files(cache_dir, source, repositories),
50        Command::Clean { target } => clean_files(target, cache_dir),
51    }
52}
53
54fn main() -> ExitCode {
55    if let Err(error) = run_command() {
56        eprintln!("{error}");
57        ExitCode::FAILURE
58    } else {
59        ExitCode::SUCCESS
60    }
61}