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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
#![allow(
clippy::cast_precision_loss,
clippy::cast_sign_loss,
clippy::match_same_arms,
clippy::cast_possible_wrap
)]
extern crate chrono;
extern crate chrono_humanize;
extern crate clap;
extern crate dirs;
extern crate libc;
extern crate lscolors;
#[cfg(test)]
extern crate tempfile;
extern crate term_grid;
extern crate terminal_size;
extern crate unicode_width;
extern crate url;
extern crate wild;
extern crate yaml_rust;
#[cfg(unix)]
extern crate users;
#[cfg(windows)]
extern crate windows;
mod app;
mod color;
mod config_file;
mod core;
mod display;
mod flags;
mod git;
mod git_theme;
mod icon;
mod meta;
mod sort;
mod theme;
use clap::Parser;
use crate::app::Cli;
use crate::config_file::Config;
use crate::core::Core;
use crate::flags::Flags;
#[derive(PartialEq, Eq, PartialOrd, Copy, Clone)]
pub enum ExitCode {
OK,
MinorIssue,
MajorIssue,
}
impl ExitCode {
pub fn set_if_greater(&mut self, code: ExitCode) {
let self_i32 = *self as i32;
let code_i32 = code as i32;
if self_i32 < code_i32 {
*self = code;
}
}
}
/// Macro used to avoid panicking when the lsd method is used with a pipe and
/// stderr close before our program.
#[macro_export]
macro_rules! print_error {
($($arg:tt)*) => {
{
use std::io::Write;
let stderr = std::io::stderr();
{
let mut handle = stderr.lock();
// We can write on stderr, so we simply ignore the error and don't print
// and stop with success.
let res = handle.write_all(std::format!("lsd: {}\n\n",
std::format!($($arg)*)).as_bytes());
if res.is_err() {
std::process::exit(0);
}
}
}
};
}
/// Macro used to avoid panicking when the lsd method is used with a pipe and
/// stdout close before our program.
#[macro_export]
macro_rules! print_output {
($($arg:tt)*) => {
use std::io::Write;
let stderr = std::io::stdout();
{
let mut handle = stderr.lock();
// We can write on stdout, so we simply ignore the error and don't print
// and stop with success.
let res = handle.write_all(std::format!($($arg)*).as_bytes());
if res.is_err() {
std::process::exit(0);
}
}
};
}
fn main() {
let cli = Cli::parse_from(wild::args_os());
let config = if cli.ignore_config {
Config::with_none()
} else if let Some(path) = &cli.config_file {
Config::from_file(path).expect("Provided file path is invalid")
} else {
Config::default()
};
let flags = Flags::configure_from(&cli, &config).unwrap_or_else(|err| err.exit());
let core = Core::new(flags);
let exit_code = core.run(cli.inputs);
std::process::exit(exit_code as i32);
}
|