majordomus/main.rs
1//! The executable: parse, log to stderr, run, exit with the contract's code.
2#![warn(missing_docs)]
3
4use std::process::ExitCode;
5
6use clap::Parser;
7
8use majordomus_cli::cli::{Cli, EXIT_USAGE};
9
10fn main() -> ExitCode {
11 // which bytes this process is, pinned before anything else runs: a server asked later
12 // whether its code still exists compares against this, not against the file at that
13 // path by then (I1502)
14 let _ = majordomus_cli::lease::started_as();
15 let cli = match Cli::try_parse() {
16 Ok(cli) => cli,
17 Err(e) => {
18 // clap prints help and version to stdout with status 0, and usage errors to
19 // stderr with status 2, which is the contract's usage code.
20 let _ = e.print();
21 return if e.use_stderr() {
22 ExitCode::from(EXIT_USAGE)
23 } else {
24 ExitCode::SUCCESS
25 };
26 }
27 };
28 majordomus_cli::logging::init();
29 match majordomus_cli::commands::run(cli) {
30 Ok(code) => ExitCode::from(code),
31 Err(err) => {
32 eprintln!("majordomus: {err}");
33 ExitCode::from(err.exit_code())
34 }
35 }
36}