bestool/lib.rs
1use std::env;
2
3use chrono::{DateTime, TimeZone, Utc};
4
5pub use crate::actions::run_with_update_check as run;
6pub use crate::args::get_args as args;
7
8pub(crate) mod actions;
9pub(crate) mod args;
10#[cfg(feature = "download")]
11pub(crate) mod download;
12pub mod find_postgres;
13
14#[cfg(feature = "tamanu-alerts")]
15pub(crate) mod postgres_to_value;
16
17#[allow(dead_code)] // some subcommands don't use it, but it's easier to have it everywhere
18pub(crate) const APP_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "-", env!("CARGO_PKG_VERSION"));
19
20#[cfg(doc)]
21pub mod __help {
22 //! Documentation-only module containing the help pages for the CLI tool.
23 //!
24 //! The [`Args`] struct contains the top level options. The [`Action`] enum contains the top
25 //! level subcommands. Beyond that, `*Args` structs contain options for that level, and
26 //! `*Action` enums contain subcommands below that level. In structs, field names are
27 //! generally transformed to options using by being kebab-cased.
28 //!
29 //! For example, [`caddy::configure_tamanu::ConfigureTamanuArgs`] represents the subcommand:
30 //!
31 //! ```text
32 //! $ bestool caddy configure-tamanu
33 //! ```
34 //!
35 //! and its fields:
36 //!
37 //! ```
38 //! # use std::{num::NonZeroU16, path::PathBuf};
39 //! pub struct ConfigureTamanuArgs {
40 //! pub path: PathBuf,
41 //! pub print: bool,
42 //! pub domain: String,
43 //! pub api_port: NonZeroU16,
44 //! pub api_version: String,
45 //! pub web_version: String,
46 //! pub email: Option<String>,
47 //! pub zerossl_api_key: Option<String>,
48 //! }
49 //! ```
50 //!
51 //! are transformed into these options:
52 //!
53 //! ```text
54 //! --path
55 //! --print
56 //! --domain
57 //! --api-port
58 //! --api-version
59 //! --web-version
60 //! --email
61 //! --zerossl-api-key
62 //! ```
63 //!
64 //! Sometimes more information is contained in the `#[clap()]` attributes like defaults and
65 //! positionals, and these can be seen by clicking the `source` link at the top right.
66
67 pub use crate::actions::*;
68 pub use crate::args::Args;
69}
70
71/// A wrapper of [`chrono::Utc::now`].
72///
73/// On debug build, this returns a fixed time if `BESTOOL_MOCK_TIME` is set.
74fn now_time<T: TimeZone>(tz: &T) -> DateTime<T> {
75 if cfg!(debug_assertions) && env::var("BESTOOL_MOCK_TIME").is_ok() {
76 DateTime::from_timestamp_nanos(0)
77 } else {
78 Utc::now()
79 }
80 .with_timezone(tz)
81}