git_simple_encrypt/
lib.rs1#![feature(vec_pop_if)]
2#![feature(let_chains)]
3#![feature(test)]
4#![warn(clippy::nursery, clippy::cargo, clippy::pedantic)]
5#![allow(clippy::multiple_crate_versions)]
6
7mod cli;
8mod config;
9mod crypt;
10mod repo;
11mod utils;
12
13use anyhow::Result;
14use crypt::{decrypt_repo, encrypt_repo};
15use log::debug;
16use repo::Repo;
17use tokio::runtime::Builder;
18
19pub use crate::cli::{Cli, SetField, SubCommand};
20
21pub fn run(cli: &Cli) -> Result<()> {
22 let repo = Repo::open(&cli.repo)?;
23 let repo = Box::leak(Box::new(repo));
24 let num_cpus = num_cpus::get();
25 debug!("using blocking thread size: {}", num_cpus * 2);
26 let rt = Builder::new_multi_thread()
27 .enable_all()
28 .max_blocking_threads(num_cpus * 2)
29 .build()
30 .unwrap();
31 rt.block_on(async {
32 match &cli.command {
33 SubCommand::Encrypt => encrypt_repo(repo).await?,
34 SubCommand::Decrypt { path } => decrypt_repo(repo, path).await?,
35 SubCommand::Add { paths } => repo
36 .conf
37 .add_to_crypt_list(&paths.iter().map(std::convert::AsRef::as_ref).collect::<Vec<_>>())?,
38 SubCommand::Set { field } => field.set(repo)?,
39 SubCommand::Pwd => repo.set_key_interactive()?,
40 }
41 anyhow::Ok::<()>(())
42 })
43}