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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*!
The `asuran-cli` binary provides a lightweight wrapper over the core `asuran`
logic, providing simple set of commands for directly interacting with
repositories.
 */
#[cfg(not(tarpaulin_include))]
mod cli;

#[cfg(not(tarpaulin_include))]
mod bench;
#[cfg(not(tarpaulin_include))]
mod contents;
#[cfg(not(tarpaulin_include))]
mod extract;
#[cfg(not(tarpaulin_include))]
mod list;
#[cfg(not(tarpaulin_include))]
mod new;
#[cfg(not(tarpaulin_include))]
mod store;

use anyhow::Result;
use cli::{Command, Opt};
use structopt::StructOpt;

cfg_if::cfg_if! {
    if #[cfg(feature = "jemallocator")] {
        #[global_allocator]
        static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
        const ALLOCATOR_NAME: &str = "jemalloc";
    } else if #[cfg(feature = "mimalloc")]{
        #[global_allocator]
        static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
        const ALLOCATOR_NAME: &str = "MiMalloc";
    } else {
        const ALLOCATOR_NAME: &str = "System Malloc";
    }
}

#[cfg(not(tarpaulin_include))]
fn main() -> Result<()> {
    let ex = smol::Executor::new();
    let ex: &'static smol::Executor = Box::leak(Box::new(ex));
    let (_signal, shutdown) = smol::channel::unbounded::<()>();
    for _ in 0..num_cpus::get_physical() {
        let shutdown = shutdown.clone();
        std::thread::spawn(move || futures::executor::block_on(ex.run(shutdown.recv())));
    }
    smol::block_on(async {
        // Our task in main is dead simple, we only need to parse the options and
        // match on the subcommand
        let options = Opt::from_args();
        let command = options.command.clone();
        match command {
            Command::New { .. } => new::new(options).await,
            Command::Store {
                target,
                name,
                glob_opts,
                ..
            } => store::store(options, target, name, glob_opts, ex).await,
            Command::List { .. } => list::list(options).await,
            Command::Extract {
                target,
                archive,
                glob_opts,
                preview,
                ..
            } => extract::extract(options, target, archive, glob_opts, preview).await,
            Command::BenchCrypto => bench::bench_crypto().await,
            Command::Contents {
                archive, glob_opts, ..
            } => contents::contents(options, archive, glob_opts).await,
        }
    })
}