1
/*!
2
The `asuran-cli` binary provides a lightweight wrapper over the core `asuran`
3
logic, providing simple set of commands for directly interacting with
4
repositories.
5
 */
6
#[cfg(not(tarpaulin_include))]
7
mod cli;
8

9
#[cfg(not(tarpaulin_include))]
10
mod bench;
11
#[cfg(not(tarpaulin_include))]
12
mod contents;
13
#[cfg(not(tarpaulin_include))]
14
mod extract;
15
#[cfg(not(tarpaulin_include))]
16
mod list;
17
#[cfg(not(tarpaulin_include))]
18
mod new;
19
#[cfg(not(tarpaulin_include))]
20
mod store;
21

22
use anyhow::Result;
23
use cli::{Command, Opt};
24
use structopt::StructOpt;
25

26
cfg_if::cfg_if! {
27
    if #[cfg(feature = "jemallocator")] {
28
        #[global_allocator]
29
        static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
30
        const ALLOCATOR_NAME: &str = "jemalloc";
31
    } else if #[cfg(feature = "mimalloc")]{
32
        #[global_allocator]
33 1
        static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
34
        const ALLOCATOR_NAME: &str = "MiMalloc";
35
    } else {
36
        const ALLOCATOR_NAME: &str = "System Malloc";
37
    }
38
}
39

40
#[cfg(not(tarpaulin_include))]
41
fn main() -> Result<()> {
42
    let ex = smol::Executor::new();
43
    let ex: &'static smol::Executor = Box::leak(Box::new(ex));
44
    let (_signal, shutdown) = smol::channel::unbounded::<()>();
45
    for _ in 0..num_cpus::get_physical() {
46
        let shutdown = shutdown.clone();
47
        std::thread::spawn(move || futures::executor::block_on(ex.run(shutdown.recv())));
48
    }
49
    smol::block_on(async {
50
        // Our task in main is dead simple, we only need to parse the options and
51
        // match on the subcommand
52
        let options = Opt::from_args();
53
        let command = options.command.clone();
54
        match command {
55
            Command::New { .. } => new::new(options).await,
56
            Command::Store { target, name, .. } => store::store(options, target, name, ex).await,
57
            Command::List { .. } => list::list(options).await,
58
            Command::Extract {
59
                target,
60
                archive,
61
                glob_opts,
62
                preview,
63
                ..
64
            } => extract::extract(options, target, archive, glob_opts, preview).await,
65
            Command::BenchCrypto => bench::bench_crypto().await,
66
            Command::Contents {
67
                archive, glob_opts, ..
68
            } => contents::contents(options, archive, glob_opts).await,
69
        }
70
    })
71
}

Read our documentation on viewing source code .

Loading