bestool/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#![deny(rust_2018_idioms)]

use std::env;

use chrono::{DateTime, TimeZone, Utc};

pub use crate::actions::{run, tamanu::find_postgres_bin};
pub use crate::args::get_args as args;

pub(crate) mod actions;
pub(crate) mod args;
#[cfg(feature = "aws")]
pub(crate) mod aws;
pub mod file_chunker;

#[cfg(feature = "tamanu-alerts")]
pub(crate) mod postgres_to_value;

#[allow(dead_code)] // some subcommands don't use it, but it's easier to have it everywhere
pub(crate) const APP_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "-", env!("CARGO_PKG_VERSION"));

#[cfg(doc)]
pub mod __help {
	//! Documentation-only module containing the help pages for the CLI tool.
	//!
	//! The [`Args`] struct contains the top level options. The [`Action`] enum contains the top
	//! level subcommands. Beyond that, `*Args` structs contain options for that level, and
	//! `*Action` enums contain subcommands below that level. In structs, field names are
	//! generally transformed to options using by being kebab-cased.
	//!
	//! For example, [`caddy::configure_tamanu::ConfigureTamanuArgs`] represents the subcommand:
	//!
	//! ```text
	//! $ bestool caddy configure-tamanu
	//! ```
	//!
	//! and its fields:
	//!
	//! ```
	//! # use std::{num::NonZeroU16, path::PathBuf};
	//! pub struct ConfigureTamanuArgs {
	//!     pub path: PathBuf,
	//!     pub print: bool,
	//!     pub domain: String,
	//!     pub api_port: NonZeroU16,
	//!     pub api_version: String,
	//!     pub web_version: String,
	//!     pub email: Option<String>,
	//!     pub zerossl_api_key: Option<String>,
	//! }
	//! ```
	//!
	//! are transformed into these options:
	//!
	//! ```text
	//! --path
	//! --print
	//! --domain
	//! --api-port
	//! --api-version
	//! --web-version
	//! --email
	//! --zerossl-api-key
	//! ```
	//!
	//! Sometimes more information is contained in the `#[clap()]` attributes like defaults and
	//! positionals, and these can be seen by clicking the `source` link at the top right.

	pub use crate::actions::*;
	pub use crate::args::Args;
}

/// A wrapper of [`chrono::Utc::now`].
///
/// On debug build, this returns a fixed time if `BESTOOL_MOCK_TIME` is set.
fn now_time<T: TimeZone>(tz: &T) -> DateTime<T> {
	if cfg!(debug_assertions) && env::var("BESTOOL_MOCK_TIME").is_ok() {
		DateTime::from_timestamp_nanos(0)
	} else {
		Utc::now()
	}
	.with_timezone(tz)
}