sos/
lib.rs

1//! Command line tools for [Save Our Secrets](https://saveoursecrets.com).
2//!
3//! This crate contains the binary for the `sos`; more information is on the
4//! [command line tools](https://saveoursecrets.com/command-line-tools/) downloads page; for the server binary see the [sos-server](https://docs.rs/sos-server/) crate.
5//!
6//! See the [CLI documentation](https://saveoursecrets.com/docs/cli/) for usage information or browse the [online help manual](https://saveoursecrets.com/docs/cli/help/); the libraries are available at [sos-sdk](https://docs.rs/sos-sdk/) and [sos-net](https://docs.rs/sos-net/).
7#![deny(missing_docs)]
8#![forbid(unsafe_code)]
9#![allow(clippy::result_large_err)]
10
11#[doc(hidden)]
12pub mod cli;
13#[doc(hidden)]
14pub mod commands;
15mod error;
16
17pub(crate) mod helpers;
18
19#[doc(hidden)]
20pub use helpers::USER;
21
22pub use sos_cli_helpers::*;
23
24#[doc(hidden)]
25pub use error::Error;
26
27/// Result type for the executable library.
28#[doc(hidden)]
29pub type Result<T> = std::result::Result<T, error::Error>;
30
31/// Run the command line tool.
32pub async fn run() -> Result<()> {
33    use kdam::term;
34    use sos_cli_helpers::messages::{fail, warn};
35    use sos_logs::Logger;
36
37    let logger: Logger = Default::default();
38    logger.init_subscriber(None)?;
39
40    if let Err(e) = crate::cli::sos::run().await {
41        if !e.is_interrupted() {
42            fail(e.to_string());
43        }
44
45        let mut owner = USER.write().await;
46        if let Err(e) = owner.sign_out_all().await {
47            warn(format!("sign out {e}"));
48        }
49
50        let _ = term::show_cursor();
51        std::process::exit(1);
52    }
53
54    Ok(())
55}