1#[macro_use]
2extern crate serde_json;
3#[macro_use]
4extern crate derive_more;
5pub mod args;
6pub mod color;
7pub mod config;
8pub mod db;
9pub mod env_pair;
10pub mod error;
11mod error_display;
12pub mod extract_msg;
13pub mod fuzzy;
14pub mod list;
15pub mod migration;
16pub mod my_env_logger;
17pub mod path;
18pub mod process_lock;
19pub mod query;
20pub mod script;
21pub mod script_repo;
22pub mod script_time;
23pub mod script_type;
24pub mod state;
25pub mod tag;
26pub mod util;
27
28pub use std::borrow::Cow;
29
30pub const APP_NAME: &str = "hs";
31pub const SEP: &str = "/";
32#[derive(Debug)]
33pub enum Either<T, U> {
34 One(T),
35 Two(U),
36}
37
38pub fn to_display_args(arg: &str) -> Cow<'_, str> {
40 fn non_whitelisted(ch: char) -> bool {
41 match ch {
42 'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' | '=' | '/' | ',' | '.' | '+' => false,
43 _ => true,
44 }
45 }
46 if !arg.is_empty() && !arg.contains(non_whitelisted) {
47 return Cow::Borrowed(arg);
48 }
49
50 let mut es = String::with_capacity(arg.len() + 2);
51 es.push('\'');
52 for ch in arg.chars() {
53 match ch {
54 '\'' | '!' => {
55 es.push_str("'\\");
56 es.push(ch);
57 es.push('\'');
58 }
59 _ => es.push(ch),
60 }
61 }
62 es.push('\'');
63 Cow::Owned(es)
64}
65
66#[cfg(not(any(feature = "no-log", feature = "log",)))]
67compile_error!("one of the features [log/no-log] must be enabled");
68
69#[cfg(all(feature = "no-log", feature = "log",))]
70compile_error!("only one of the features [log/no-log] can be enabled");