-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathlib.rs
More file actions
104 lines (92 loc) · 2.67 KB
/
lib.rs
File metadata and controls
104 lines (92 loc) · 2.67 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use {
self::{
arguments::Arguments, display_path::DisplayPath, display_secret::DisplaySecret, error::Error,
lint::Lint, lint_group::LintGroup, list::List, manifest::Manifest, metadata::Metadata,
options::Options, owo_colorize_ext::OwoColorizeExt, private_key::PrivateKey,
public_key::PublicKey, relative_path::RelativePath, signature::Signature,
signature_error::SignatureError, style::Style, subcommand::Subcommand, template::Template,
utf8_path_ext::Utf8PathExt,
},
blake3::Hasher,
camino::{Utf8Component, Utf8Path, Utf8PathBuf},
clap::{Parser, ValueEnum},
indicatif::{ProgressBar, ProgressStyle},
lexiclean::Lexiclean,
owo_colors::Styled,
serde::{Deserialize, Deserializer, Serialize, Serializer},
serde_with::{DeserializeFromStr, SerializeDisplay},
snafu::{ensure, ErrorCompat, OptionExt, ResultExt, Snafu},
std::{
array::TryFromSliceError,
backtrace::{Backtrace, BacktraceStatus},
cmp::Ordering,
collections::{BTreeMap, HashMap},
env,
fmt::{self, Display, Formatter},
fs::File,
io::{self, IsTerminal},
path::{Path, PathBuf},
process,
str::{self, FromStr},
},
walkdir::WalkDir,
};
pub use self::{entry::Entry, hash::Hash};
#[cfg(test)]
use assert_fs::TempDir;
mod arguments;
mod display_path;
mod display_secret;
mod entry;
mod error;
mod filesystem;
mod hash;
mod lint;
mod lint_group;
mod list;
mod manifest;
mod metadata;
mod options;
mod owo_colorize_ext;
mod private_key;
mod progress_bar;
mod public_key;
mod relative_path;
mod signature;
mod signature_error;
mod style;
mod subcommand;
mod template;
mod utf8_path_ext;
type Result<T = (), E = Error> = std::result::Result<T, E>;
const MASTER_PRIVATE_KEY: &str = "master.private";
const MASTER_PUBLIC_KEY: &str = "master.public";
fn current_dir() -> Result<Utf8PathBuf> {
Utf8PathBuf::from_path_buf(env::current_dir().context(error::CurrentDir)?)
.map_err(|path| error::PathUnicode { path }.build())
}
fn decode_path(path: &Path) -> Result<&Utf8Path> {
Utf8Path::from_path(path).context(error::PathUnicode { path })
}
pub fn run() {
if let Err(err) = Arguments::parse().run() {
let style = Style::stderr();
eprintln!(
"{}: {}",
"error".style(style.error()),
err.style(style.message()),
);
let causes = err.iter_chain().skip(1).count();
for (i, err) in err.iter_chain().skip(1).enumerate() {
eprintln!(" {}─ {err}", if i < causes - 1 { '├' } else { '└' });
}
if let Some(backtrace) = err.backtrace() {
if backtrace.status() == BacktraceStatus::Captured {
eprintln!();
eprintln!("backtrace:");
eprintln!("{backtrace}");
}
}
process::exit(1);
}
}