Skip to content

Commit bf3c078

Browse files
authored
Merge pull request #7 from petros/fix-error-handling
Fix error handling and get the version from Cargo.toml
2 parents eed3cff + 6b5e11a commit bf3c078

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "drem"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

scripts/publish.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
echo "Building a release version of the project..."
4+
cargo build --release
5+
6+
echo "Copying the binary to the target directory..."
7+
echo "Current directory: $(pwd)"
8+
sudo cp target/release/drem /usr/local/bin/drem
9+
10+
echo "Done!"

src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ use std::{
88
use zip::ZipArchive;
99

1010
fn files_exist_in_archive(drgtk: &PathBuf, files: &[&str]) -> bool {
11-
let reader = File::open(drgtk).unwrap();
11+
let reader = match File::open(drgtk) {
12+
Ok(file) => file,
13+
Err(error) => {
14+
eprintln!("Could not open DRGTK: {}", error);
15+
return false;
16+
}
17+
};
1218
let mut archive = ZipArchive::new(reader).unwrap();
1319
let mut result = true;
1420
for file_name in files {
@@ -116,8 +122,9 @@ fn build_new_subcommand() -> Command {
116122
}
117123

118124
fn build_command() -> Command {
125+
let version = env!("CARGO_PKG_VERSION");
119126
Command::new("drem")
120-
.version("0.2.0")
127+
.version(version)
121128
.subcommand(build_new_subcommand())
122129
}
123130

@@ -135,10 +142,12 @@ fn main() {
135142
}
136143
Err(e) => {
137144
println!("Error: {}", e);
145+
std::process::exit(1);
138146
}
139147
}
140148
} else {
141149
println!("DRGTK is not a valid macOS archive");
150+
std::process::exit(1);
142151
}
143152
}
144153
}

0 commit comments

Comments
 (0)