summaryrefslogtreecommitdiff
path: root/src/chunker/entry.rs
blob: 4fdb1f8d935ca6830a842225348312bba8bc5bce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::process::exit;

use log::info;

use crate::chunker::{
    context::ButckContext,
    rw::{self, error::ButckRWError},
};

pub async fn entry(ctx: ButckContext, args: Vec<String>) -> Result<(), ButckRWError> {
    if let Some(subcommand) = args.first() {
        return match subcommand.as_str() {
            "write" => rw::storage::write(ctx).await,
            "build" => rw::storage::build(ctx).await,
            "policies" => {
                butck_policies::policies()
                    .iter()
                    .for_each(|p| info!("{}", p));
                return Ok(());
            }
            _ => {
                print_help();
                exit(1)
            }
        };
    }
    Ok(())
}

pub fn print_help() {
    println!("{}", include_str!("../../resources/helps/butck.txt").trim());
}

pub fn print_version() {
    println!(
        "{}",
        include_str!("../../resources/version_info.txt").trim()
    );
}