|
| 1 | +use { |
| 2 | + self::{ |
| 3 | + arguments::Arguments, display_path::DisplayPath, display_secret::DisplaySecret, error::Error, |
| 4 | + lint::Lint, lint_group::LintGroup, list::List, manifest::Manifest, metadata::Metadata, |
| 5 | + options::Options, owo_colorize_ext::OwoColorizeExt, private_key::PrivateKey, |
| 6 | + public_key::PublicKey, relative_path::RelativePath, signature::Signature, |
| 7 | + signature_error::SignatureError, style::Style, subcommand::Subcommand, template::Template, |
| 8 | + utf8_path_ext::Utf8PathExt, |
| 9 | + }, |
| 10 | + blake3::Hasher, |
| 11 | + camino::{Utf8Component, Utf8Path, Utf8PathBuf}, |
| 12 | + clap::{Parser, ValueEnum}, |
| 13 | + indicatif::{ProgressBar, ProgressStyle}, |
| 14 | + lexiclean::Lexiclean, |
| 15 | + owo_colors::Styled, |
| 16 | + serde::{Deserialize, Deserializer, Serialize, Serializer}, |
| 17 | + serde_with::{DeserializeFromStr, SerializeDisplay}, |
| 18 | + snafu::{ensure, ErrorCompat, OptionExt, ResultExt, Snafu}, |
| 19 | + std::{ |
| 20 | + array::TryFromSliceError, |
| 21 | + backtrace::{Backtrace, BacktraceStatus}, |
| 22 | + cmp::Ordering, |
| 23 | + collections::{BTreeMap, HashMap}, |
| 24 | + env, |
| 25 | + fmt::{self, Display, Formatter}, |
| 26 | + fs::File, |
| 27 | + io::{self, IsTerminal}, |
| 28 | + path::{Path, PathBuf}, |
| 29 | + process, |
| 30 | + str::{self, FromStr}, |
| 31 | + }, |
| 32 | + walkdir::WalkDir, |
| 33 | +}; |
| 34 | + |
| 35 | +pub use self::{entry::Entry, hash::Hash}; |
| 36 | + |
| 37 | +#[cfg(test)] |
| 38 | +use assert_fs::TempDir; |
| 39 | + |
| 40 | +mod arguments; |
| 41 | +mod display_path; |
| 42 | +mod display_secret; |
| 43 | +mod entry; |
| 44 | +mod error; |
| 45 | +mod filesystem; |
| 46 | +mod hash; |
| 47 | +mod lint; |
| 48 | +mod lint_group; |
| 49 | +mod list; |
| 50 | +mod manifest; |
| 51 | +mod metadata; |
| 52 | +mod options; |
| 53 | +mod owo_colorize_ext; |
| 54 | +mod private_key; |
| 55 | +mod progress_bar; |
| 56 | +mod public_key; |
| 57 | +mod relative_path; |
| 58 | +mod signature; |
| 59 | +mod signature_error; |
| 60 | +mod style; |
| 61 | +mod subcommand; |
| 62 | +mod template; |
| 63 | +mod utf8_path_ext; |
| 64 | + |
| 65 | +type Result<T = (), E = Error> = std::result::Result<T, E>; |
| 66 | + |
| 67 | +const MASTER_PRIVATE_KEY: &str = "master.private"; |
| 68 | +const MASTER_PUBLIC_KEY: &str = "master.public"; |
| 69 | + |
| 70 | +fn current_dir() -> Result<Utf8PathBuf> { |
| 71 | + Utf8PathBuf::from_path_buf(env::current_dir().context(error::CurrentDir)?) |
| 72 | + .map_err(|path| error::PathUnicode { path }.build()) |
| 73 | +} |
| 74 | + |
| 75 | +fn decode_path(path: &Path) -> Result<&Utf8Path> { |
| 76 | + Utf8Path::from_path(path).context(error::PathUnicode { path }) |
| 77 | +} |
| 78 | + |
| 79 | +pub fn run() { |
| 80 | + if let Err(err) = Arguments::parse().run() { |
| 81 | + let style = Style::stderr(); |
| 82 | + eprintln!( |
| 83 | + "{}: {}", |
| 84 | + "error".style(style.error()), |
| 85 | + err.style(style.message()), |
| 86 | + ); |
| 87 | + |
| 88 | + let causes = err.iter_chain().skip(1).count(); |
| 89 | + |
| 90 | + for (i, err) in err.iter_chain().skip(1).enumerate() { |
| 91 | + eprintln!(" {}─ {err}", if i < causes - 1 { '├' } else { '└' }); |
| 92 | + } |
| 93 | + |
| 94 | + if let Some(backtrace) = err.backtrace() { |
| 95 | + if backtrace.status() == BacktraceStatus::Captured { |
| 96 | + eprintln!(); |
| 97 | + eprintln!("backtrace:"); |
| 98 | + eprintln!("{backtrace}"); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + process::exit(1); |
| 103 | + } |
| 104 | +} |
0 commit comments