refractr/src/main.rs

57 lines
1.6 KiB
Rust

mod common;
mod config;
use clap::Parser;
use std::path::PathBuf;
use std::process;
#[derive(Parser)]
#[command(name = "refractor")]
#[command(version = "0.1.0")]
#[command(about = "An automated push/pull/clone utility for mirroring Git repositories")]
#[command(long_about = None)]
struct Args {
#[arg(short, long, help = "Specify a config file", default_value = get_config_default())]
config: Vec<PathBuf>,
#[arg(short, long, help = "Specify the level of verbosity", action = clap::ArgAction::Count)]
verbose: u8,
#[arg(short = 'e', long, help = "Output a full, commented config file and exit")]
create: bool,
}
fn get_config_default() -> &'static str {
if cfg!(windows) {
"C:\\ProgramData\\refractr\\config.toml"
} else {
"/etc/refractr/config.toml"
}
}
fn main() {
let args = Args::parse();
let refractr = common::Refractr {
verbose: args.verbose,
pid: process::id(),
unix: cfg!(unix)
};
common::verbose(refractr.verbose, 1, format!("Level {} verbosity enabled", refractr.verbose.to_string()));
common::verbose(refractr.verbose, 2, format!("Checking for create flag"));
if args.create {
common::verbose(refractr.verbose, 3, format!("Printing sample config"));
let example = include_str!("example/config.toml");
println!("{}", example);
} else {
let cfgs = config::read_config(args.config, &refractr);
if refractr.verbose >= 2 {
// no need to loop over configs if verbose is not at the correct level
for i in cfgs {
common::verbose(refractr.verbose, 2, format!("{}", i));
}
}
common::verbose(refractr.verbose, 1, format!("Config file(s) read successfully"));
}
}