summaryrefslogtreecommitdiff
path: root/src/entry.rs
blob: f1d5203e8e1f3d80e09c2e5bafec96ede14ee6ef (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
40
41
42
43
44
45
46
47
48
49
50
use std::process::exit;

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,
            "lspolicy" => {
                if ctx.stream_read.is_some() {
                    butck_policies::stream_policies()
                        .iter()
                        .for_each(|p| println!("{}", p));
                } else {
                    butck_policies::policies()
                        .iter()
                        .for_each(|p| println!("{}", p));
                }
                return Ok(());
            }
            "lspolicy-all" => {
                let policies = butck_policies::policies();
                let stream_policies = butck_policies::stream_policies();
                let mut all_policies: Vec<_> =
                    policies.iter().chain(stream_policies.iter()).collect();
                all_policies.sort();
                all_policies.dedup();
                all_policies.iter().for_each(|p| println!("{}", 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());
}