summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index ccae56f..eb71ec6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,20 +10,31 @@ fn main() {
println!("api: {}", api);
}
- if let Some(_) = matches.subcommand_matches("version") {
- version();
- } else if let Some(_) = matches.subcommand_matches("status") {
- status();
- } else {
- eprintln!("no action taken!");
- std::process::exit(1);
- }
+ let code = match matches.subcommand_name() {
+ Some("version") => version(),
+ Some("status") => status(),
+ None => none(),
+ _ => unknown(),
+ };
+ std::process::exit(code);
+}
+
+fn none() -> i32 {
+ eprintln!("No subcommand was given");
+ 1
+}
+
+fn unknown() -> i32 {
+ eprintln!("Unknown command");
+ 1
}
-fn version() {
- println!("status requested");
+fn version() -> i32 {
+ println!("status requested");
+ 0
}
-fn status() {
- println!("status requested");
+fn status() -> i32 {
+ println!("status requested");
+ 0
}