1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
compose-updater/src/main.rs

63 lines
1.3 KiB
Rust
Raw Normal View History

2020-10-05 17:59:05 +01:00
#[macro_use]
extern crate log;
use glob::glob;
use std::path::PathBuf;
2020-10-05 17:36:44 +01:00
use std::process::exit;
use structopt::StructOpt;
2020-10-05 17:36:44 +01:00
mod compose;
#[derive(StructOpt, Debug)]
#[structopt()]
struct Opt {
#[structopt(name = "files")]
files: Vec<String>,
2020-10-05 17:59:05 +01:00
#[structopt(short, long)]
verbose: bool,
}
fn get_files(files: &[String]) -> Option<Vec<PathBuf>> {
let mut all_files = Vec::new();
for file in files {
for path in glob(&file).ok()?.filter_map(Result::ok) {
if path.is_file() {
all_files.push(path);
}
}
}
Some(all_files)
}
2020-10-05 14:36:41 +01:00
fn main() {
let opts = Opt::from_args();
2020-10-05 17:59:05 +01:00
env_logger::builder()
.format_timestamp(None)
.filter_level(if opts.verbose {
log::LevelFilter::Debug
} else {
log::LevelFilter::Info
})
.format_module_path(false)
.init();
2020-10-05 17:36:44 +01:00
if opts.files.is_empty() {
2020-10-05 17:59:05 +01:00
error!("Must specify some files");
2020-10-05 17:36:44 +01:00
exit(1);
}
2020-10-05 17:59:05 +01:00
debug!("Searching for files...");
2020-10-05 17:36:44 +01:00
let compose_files = match get_files(&opts.files) {
Some(f) => f,
None => exit(1),
};
let compose_projects: Vec<compose::ComposeProject> = compose_files
.iter()
.map(compose::ComposeProject::new)
.collect();
2020-10-05 17:59:05 +01:00
info!("Found {} projects", compose_projects.len());
2020-10-05 14:36:41 +01:00
}