Skip to main content

andysu_cli/
lib.rs

1//! Library half of the `andysu` CLI (the binary is a thin clap front end), so integration tests
2//! can call the same code.
3
4pub mod apk;
5pub mod axml;
6pub mod elf;
7pub mod hostapk;
8pub mod init;
9pub mod keys;
10pub mod pack;
11pub mod publish;
12pub mod serve;
13pub mod split;
14
15pub type R<T> = Result<T, String>;
16
17pub fn now() -> i64 {
18    std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() as i64
19}
20
21pub fn random<const N: usize>() -> [u8; N] {
22    let mut b = [0u8; N];
23    getrandom::getrandom(&mut b).expect("OS randomness");
24    b
25}
26
27pub fn read(p: &std::path::Path) -> R<Vec<u8>> {
28    std::fs::read(p).map_err(|e| format!("read {}: {e}", p.display()))
29}
30
31pub fn write(p: &std::path::Path, b: &[u8]) -> R<()> {
32    if let Some(d) = p.parent() {
33        std::fs::create_dir_all(d).map_err(|e| format!("mkdir {}: {e}", d.display()))?;
34    }
35    std::fs::write(p, b).map_err(|e| format!("write {}: {e}", p.display()))
36}