ssec_cli/
lib.rs

1#![forbid(unsafe_code)]
2
3pub mod cli;
4
5mod file;
6mod io;
7mod password;
8mod enc;
9mod dec;
10
11#[cfg(test)]
12mod tests;
13
14const DEFINITE_BAR_STYLE: &str = "[{elapsed_precise}] {binary_bytes_per_sec} {bar} {binary_bytes}/{binary_total_bytes} ({eta})";
15const INDEFINITE_BAR_STYLE: &str = "[{elapsed_precise}] {binary_bytes_per_sec} ({eta})";
16
17#[inline]
18fn handle_err(result: Result<(), ()>) -> std::process::ExitCode {
19	match result {
20		Ok(()) => std::process::ExitCode::SUCCESS,
21		Err(()) => std::process::ExitCode::FAILURE
22	}
23}
24
25async fn run_with_io<B: io::IoBundle>(cli: cli::Cli, io: B) -> std::process::ExitCode {
26	match cli.command {
27		cli::Command::Enc(args) => handle_err(enc::enc(args, io).await),
28		cli::Command::Dec(args) => handle_err(dec::dec_file(args, io).await),
29		cli::Command::Fetch(args) => handle_err(dec::dec_fetch(args, io).await)
30	}
31}
32
33pub async fn run(cli: cli::Cli) -> std::process::ExitCode {
34	run_with_io(cli, io::InteractiveIo).await
35}