bestool/lib.rs
1use std::env;
2
3pub use crate::actions::run_with_update_check as run;
4pub use crate::args::get_args as args;
5
6pub(crate) mod actions;
7pub(crate) mod args;
8#[cfg(all(
9 test,
10 feature = "canopy-register",
11 feature = "tamanu-artifacts",
12 feature = "tamanu-psql"
13))]
14mod canopy_contract;
15#[cfg(feature = "download")]
16pub(crate) mod download;
17pub mod find_postgres;
18pub(crate) mod http;
19#[cfg(feature = "canopy-restore")]
20pub(crate) mod interactive;
21
22#[cfg(doc)]
23pub mod __help {
24 //! Documentation-only module containing the help pages for the CLI tool.
25 //!
26 //! The [`Args`] struct contains the top level options. The [`Action`] enum contains the top
27 //! level subcommands. Beyond that, `*Args` structs contain options for that level, and
28 //! `*Action` enums contain subcommands below that level. In structs, field names are
29 //! generally transformed to options using by being kebab-cased.
30 //!
31 //! For example, [`caddy::upgrade::UpgradeArgs`] represents the subcommand:
32 //!
33 //! ```text
34 //! $ bestool caddy upgrade
35 //! ```
36 //!
37 //! and its fields:
38 //!
39 //! ```
40 //! pub struct UpgradeArgs {
41 //! pub version: String,
42 //! pub target: Option<String>,
43 //! }
44 //! ```
45 //!
46 //! are transformed into these options:
47 //!
48 //! ```text
49 //! --version
50 //! --target
51 //! ```
52 //!
53 //! Sometimes more information is contained in the `#[clap()]` attributes like defaults and
54 //! positionals, and these can be seen by clicking the `source` link at the top right.
55
56 pub use crate::actions::*;
57 pub use crate::args::Args;
58}
59
60/// A wrapper of [`jiff::Timestamp::now`].
61///
62/// On debug build, this returns the unix epoch if `BESTOOL_MOCK_TIME` is set.
63fn now_time() -> jiff::Timestamp {
64 if cfg!(debug_assertions) && env::var("BESTOOL_MOCK_TIME").is_ok() {
65 jiff::Timestamp::UNIX_EPOCH
66 } else {
67 jiff::Timestamp::now()
68 }
69}