1pub mod env;
4pub mod pkg;
5
6#[macro_export]
7macro_rules! lazy_motd {
8 (copyright = [$($copyright_line:expr),* $(,)?] $(, $key:ident = $val:expr)* $(,)?) => {{
9 let copyright_lines: &[&str] = &[$($copyright_line),*];
10 $crate::lazy_motd!(copyright = copyright_lines $(, $key = $val)*);
11 }};
12
13 ($( $key:ident = $val:expr ),* $(,)?) => {{
14 let mut bin: Option<&str> = None;
15 let mut build: Option<&str> = None;
16 let mut mode: Option<&str> = None;
17 let mut timestamp: Option<&str> = None;
18 let mut environment: Option<&str> = None;
19 let mut copyright: Option<&[&str]> = None;
20
21 $(
22 lazy_motd!(@assign $key = $val, bin, build, mode, timestamp, environment, copyright);
23 )*
24 let final_pkg_name = if let Some(b) = bin {
25 if b == "None" {
26 env!("CARGO_BIN_NAME").to_string()
28 } else if !b.is_empty() {
29 $crate::pkg::capitalize_first(b)
31 } else {
32 $crate::pkg::capitalize_first(env!("CARGO_PKG_NAME"))
34 }
35 } else {
36 $crate::pkg::capitalize_first(env!("CARGO_PKG_NAME"))
38 };
39
40 if let Err(e) = $crate::pkg::print_motd(
41 &final_pkg_name, build.unwrap_or("Preview"),
43 $crate::pkg::MotdOptions {
44 mode,
45 timestamp,
46 environment,
47 copyright,
48 }
49 ) {
50 eprintln!("Failed to print motd: {}", e);
51 }
52 }};
53
54 (@assign bin = $val:expr, $bin:ident, $build:ident, $mode:ident, $timestamp:ident, $environment:ident, $copyright:ident) => {
55 $bin = Some($val);
56 };
57 (@assign build = $val:expr, $bin:ident, $build:ident, $mode:ident, $timestamp:ident, $environment:ident, $copyright:ident) => {
58 $build = Some($val);
59 };
60 (@assign mode = $val:expr, $bin:ident, $build:ident, $mode:ident, $timestamp:ident, $environment:ident, $copyright:ident) => {
61 $mode = Some($val);
62 };
63 (@assign timestamp = $val:expr, $bin:ident, $build:ident, $mode:ident, $timestamp:ident, $environment:ident, $copyright:ident) => {
64 $timestamp = Some($val);
65 };
66 (@assign environment = $val:expr, $bin:ident, $build:ident, $mode:ident, $timestamp:ident, $environment:ident, $copyright:ident) => {
67 $environment = Some($val);
68 };
69 (@assign copyright = $val:expr, $bin:ident, $build:ident, $mode:ident, $timestamp:ident, $environment:ident, $copyright:ident) => {
70 $copyright = Some($val);
71 };
72
73 () => {
74 $crate::lazy_motd!(bin = "", build = "Preview");
75 };
76}