Skip to content

Commit 9061b91

Browse files
authored
Merge pull request #35 from iancleary/feat/better-error-messaging
Updated error message and color
2 parents 2ad067e + 82ac33c commit 9061b91

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
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
@@ -7,7 +7,7 @@ homepage = "https://github.com/iancleary/touchstone"
77
license = "MIT"
88
name = "touchstone"
99
repository = "https://github.com/iancleary/touchstone"
10-
version = "0.10.1"
10+
version = "0.10.2"
1111

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

src/cli.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,24 @@ impl Config {
128128
}
129129
}
130130

131-
fn print_version() {
131+
pub fn print_version() {
132132
println!("touchstone {}", env!("CARGO_PKG_VERSION"));
133133
}
134134

135-
fn print_help() {
135+
pub fn print_error(error: &str) {
136+
const RED: &str = "\x1b[31m";
137+
const RESET: &str = "\x1b[0m";
138+
println!("{}Problem parsing arguments: {error}{}", RED, RESET);
139+
}
140+
141+
pub fn print_help() {
136142
// ANSI color codes
137143
const BOLD: &str = "\x1b[1m";
138144
const CYAN: &str = "\x1b[36m";
139145
const GREEN: &str = "\x1b[32m";
140146
const YELLOW: &str = "\x1b[33m";
141147
const RESET: &str = "\x1b[0m";
142148

143-
println!();
144149
println!(
145150
"📡 Touchstone (s2p, etc.) file parser, plotter, and more - https://github.com/iancleary/touchstone{}",
146151
RESET

src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ fn main() {
77
let args: Vec<String> = env::args().collect();
88

99
let _ = cli::Config::run(&args).unwrap_or_else(|err| {
10-
println!("Problem parsing arguments: {err}");
10+
println!();
11+
cli::print_error(err); //print at the top, but might be lost or hard to read
12+
println!();
13+
cli::print_help();
14+
println!();
15+
cli::print_error(err); // print error again, for human factors
1116
process::exit(1);
1217
});
1318
}

0 commit comments

Comments
 (0)