Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
timburks committed Dec 2, 2023
1 parent d1b4233 commit 44c17d8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ $ cli calc -op sub 10 6 3 2
### Top level error handling

```rust
use seahorse::{App, Context, Error, Flag, FlagType};
use seahorse::{App, Context, Flag, FlagType};
use std::env;

fn main() {
Expand All @@ -251,9 +251,7 @@ fn main() {
.version(env!("CARGO_PKG_VERSION"))
.action_with_result(|c: &Context| {
if c.bool_flag("error") {
Err(Error {
message: "ERROR...".to_string(),
})
Err(Box::new(Error))
} else {
Ok(())
}
Expand All @@ -266,11 +264,20 @@ fn main() {

match app.run_with_result(args) {
Ok(_) => println!("OK"),
Err(e) => match e {
Error { message } => println!("{}", message),
},
Err(e) => println!("{:?}", e),
};
}

#[derive(Debug, Clone)]
struct Error;

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ERROR...")
}
}

impl std::error::Error for Error {}
```

```bash
Expand Down

0 comments on commit 44c17d8

Please sign in to comment.