Skip to main content

criner_cli/
lib.rs

1use std::ops::Add;
2
3mod args;
4pub mod error;
5pub use args::*;
6
7pub fn run_blocking(args: Args) -> criner::error::Result<()> {
8    use SubCommands::*;
9    let cmd = args.sub.unwrap_or_default();
10    match cmd {
11        #[cfg(feature = "migration")]
12        Migrate => criner::migration::migrate("./criner.db"),
13        Export {
14            input_db_path,
15            export_db_path,
16        } => criner::export::run_blocking(input_db_path, export_db_path),
17        Mine {
18            repository,
19            db_path,
20            fps,
21            time_limit,
22            io_bound_processors,
23            cpu_bound_processors,
24            cpu_o_bound_processors,
25            no_gui,
26            no_db_download,
27            progress_message_scrollback_buffer_size,
28            fetch_every,
29            fetch_at_most,
30            process_at_most,
31            process_every,
32            download_crates_io_database_every_24_hours_starting_at,
33            report_every,
34            report_at_most,
35            glob,
36        } => criner::run::blocking(
37            db_path,
38            repository.unwrap_or_else(|| std::env::temp_dir().join("criner-crates-io-bare-index.git")),
39            time_limit.map(|d| std::time::SystemTime::now().add(*d)),
40            io_bound_processors,
41            cpu_bound_processors,
42            cpu_o_bound_processors,
43            !no_db_download,
44            criner::run::StageRunSettings {
45                every: fetch_every.into(),
46                at_most: fetch_at_most,
47            },
48            criner::run::StageRunSettings {
49                every: process_every.into(),
50                at_most: process_at_most,
51            },
52            criner::run::GlobStageRunSettings {
53                run: criner::run::StageRunSettings {
54                    every: report_every.into(),
55                    at_most: report_at_most,
56                },
57                glob,
58            },
59            download_crates_io_database_every_24_hours_starting_at,
60            criner::prodash::tree::root::Options {
61                message_buffer_capacity: progress_message_scrollback_buffer_size,
62                ..criner::prodash::tree::root::Options::default()
63            }
64            .create()
65            .into(),
66            if no_gui {
67                None
68            } else {
69                Some(criner::prodash::render::tui::Options {
70                    title: "Criner".into(),
71                    frames_per_second: fps,
72                    recompute_column_width_every_nth_frame: Option::from(fps as usize),
73                    ..criner::prodash::render::tui::Options::default()
74                })
75            },
76        ),
77    }
78}