summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-10-28 19:17:13 +0200
committerLars Wirzenius <liw@liw.fi>2018-10-28 19:17:13 +0200
commite33685f77b5de5dd1d45a09d6e15c50c1afe7a94 (patch)
tree2ec23ae10464c2e16e19e8cbd73325a12f931d36
parentaa51e17f0252da3760bdf7b3e883a1955f9ce8dd (diff)
downloadicktool-rs-master.tar.gz
Refactor: how the right function gets called for a subcommandHEADmaster
-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
}