Skip to content

Commit 2e292d6

Browse files
committed
Better formatted graceful exit notification
1 parent 8aa3a81 commit 2e292d6

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

Cargo.toml

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cmiv-cli"
3-
version = "0.1.8"
3+
version = "0.1.9"
44
edition = "2021"
55
repository = "https://github.com/CM-IV/cmiv-CLI"
66

@@ -23,7 +23,12 @@ codegen-units = 1
2323

2424
# The profile that 'cargo dist' will build with
2525
[profile.dist]
26-
inherits = "release"
26+
lto = "fat"
27+
opt-level = "z"
28+
debug = 0
29+
overflow-checks = false
30+
panic = "abort"
31+
codegen-units = 1
2732

2833
# Config for 'cargo dist'
2934
[workspace.metadata.dist]

src/main.rs

+10-31
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,9 @@ fn main() {
2525
.expect("Error setting Ctrl-C handler");
2626
}
2727

28-
if let Err(e) = cliclack::clear_screen() {
29-
eprintln!("Error clearing screen: {}", e);
30-
exit(1);
31-
}
28+
cliclack::clear_screen().unwrap();
3229

33-
if let Err(e) = cliclack::intro("CM-IV CLI".on_cyan().black()) {
34-
eprintln!("Error showing intro: {}", e);
35-
exit(1);
36-
}
30+
cliclack::intro("CM-IV CLI".on_cyan().black()).unwrap();
3731

3832
let path = match cliclack::input("Where should we create your project?")
3933
.placeholder("./sparkling-solid")
@@ -49,12 +43,12 @@ fn main() {
4943
.interact()
5044
{
5145
Ok(path) => path,
52-
Err(e) => {
46+
Err(_) => {
5347
if should_terminate.load(Ordering::SeqCst) {
54-
println!("\nGracefully exiting...");
48+
cliclack::log::remark("\nGracefully exiting...").unwrap();
5549
exit(0);
5650
} else {
57-
eprintln!("Error with input: {}", e);
51+
cliclack::log::error("\nError with input, exiting...").unwrap();
5852
exit(1);
5953
}
6054
}
@@ -73,12 +67,12 @@ fn main() {
7367
.interact()
7468
{
7569
Ok(kind) => kind,
76-
Err(e) => {
70+
Err(_) => {
7771
if should_terminate.load(Ordering::SeqCst) {
78-
println!("Gracefully exiting...");
72+
cliclack::log::remark("\nGracefully exiting...").unwrap();
7973
exit(0);
8074
} else {
81-
eprintln!("Error with selection: {}", e);
75+
cliclack::log::error("\nError with selection, exiting...").unwrap();
8276
exit(1);
8377
}
8478
}
@@ -98,14 +92,6 @@ fn copy_template(install_path: String, kind: &str, dirs: &[DirEntry]) {
9892

9993
let extracted_template_path = d.path().join(kind);
10094

101-
if !extracted_template_path.exists() {
102-
eprintln!(
103-
"Template path does not exist: {}",
104-
extracted_template_path.display()
105-
);
106-
continue;
107-
}
108-
10995
let target_path = std::path::Path::new(&format!(
11096
"{}/{}",
11197
std::env::current_dir().unwrap().display(),
@@ -119,23 +105,16 @@ fn copy_template(install_path: String, kind: &str, dirs: &[DirEntry]) {
119105
}
120106

121107
let mut entries: Vec<PathBuf> = vec![];
108+
122109
if let Ok(dir_entries) = std::fs::read_dir(&extracted_template_path) {
123110
for entry in dir_entries {
124111
if let Ok(entry) = entry {
125112
entries.push(entry.path());
126113
}
127114
}
128-
} else {
129-
eprintln!(
130-
"Failed to read directory: {}",
131-
extracted_template_path.display()
132-
);
133-
continue;
134115
}
135116

136-
let options = CopyOptions::new();
137-
138-
match fs_extra::copy_items(&entries, &target_path, &options) {
117+
match fs_extra::copy_items(&entries, &target_path, &CopyOptions::new()) {
139118
Ok(_) => {
140119
cliclack::outro("All finished, thanks for using CM-IV CLI!".green()).unwrap();
141120
}

0 commit comments

Comments
 (0)