acorn-cli 0.1.50

ACORN command line interface
use crate::config::ApplicationConfiguration;
use acorn::prelude::PathBuf;
use acorn::util::{suffix, Label};
use color_eyre::eyre::{Report, Result};
use owo_colors::OwoColorize;
use std::process::exit;
use tracing::error;

pub fn run(buckets: &Option<PathBuf>, output: &Option<PathBuf>, offline: &bool) -> Result<(), Report> {
    if *offline {
        println!("=> {} ACORN is running in offline mode", Label::fmt_skip("OFFLINE"));
    }
    if let Some(path) = buckets {
        match ApplicationConfiguration::read(path.clone()) {
            | Some(content) => {
                let mut total: usize = 0;
                content.buckets.into_iter().for_each(|bucket| {
                    if let Some(path) = output {
                        total += if *offline || bucket.clone().code_repository.is_local() {
                            bucket.copy_files(path.to_path_buf())
                        } else {
                            bucket.download_files(path.to_path_buf())
                        }
                    }
                });
                println!("\n\n   => {} Processed {} item{}\n", Label::pass(), total.green(), suffix(total));
            }
            | None => {
                error!("=> {} Download data", Label::fail());
                exit(exitcode::DATAERR);
            }
        };
    }
    Ok(())
}