1pub mod help;
3pub mod sys;
5
6use std::mem::transmute;
7
8use sys::{action::ActMap, app::App, init::Mode, log::Log};
9
10pub fn run(name: &str, version: &str, desc: &str, func: impl Fn() -> ActMap) {
12 let app = match execute(name, version, desc, &func, true) {
13 Some(app) => app,
14 None => return,
15 };
16 if let Mode::Go = app.init.mode {
17 if app.init.conf.is_default {
18 execute(name, version, desc, &func, false);
19 }
20 }
21}
22
23fn execute(name: &str, version: &str, desc: &str, func: &impl Fn() -> ActMap, allow_no_config: bool) -> Option<App> {
25 let app = match App::new(name, version, desc, allow_no_config) {
26 Some(a) => a,
27 None => return None,
28 };
29 Log::info(200, None);
30 app.run(func);
31 Log::info(201, None);
32 Some(app)
33}
34
35#[inline]
45pub fn fnv1a_64(bytes: &[u8]) -> i64 {
46 let mut hash = 0xcbf29ce484222325;
47 for c in bytes {
48 hash ^= u64::from(*c);
49 hash = hash.wrapping_mul(0x100000001b3);
50 }
51 unsafe { transmute(hash) }
52}
53
54pub trait StrOrI64 {
56 fn to_i64(&self) -> i64;
58 fn to_str(&self) -> &str;
60}
61
62impl StrOrI64 for i64 {
63 fn to_i64(&self) -> i64 {
66 *self
67 }
68 fn to_str(&self) -> &str {
70 ""
71 }
72}
73
74impl StrOrI64 for &str {
75 fn to_i64(&self) -> i64 {
78 fnv1a_64(self.as_bytes())
79 }
80 fn to_str(&self) -> &str {
83 self
84 }
85}