Skip to main content

dev_scripts/
main.rs

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