aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-26 21:55:21 +0000
committerFuwn <[email protected]>2021-05-26 21:55:21 +0000
commit976ac6e5690449e9dcda954444efef639632bf91 (patch)
tree5f0624ab49c2378b5e5617e948fac7a13361f37b
parentMerge pull request #36 from Whirlsplash/renovate/sysinfo-0.x (diff)
downloadwhirl-976ac6e5690449e9dcda954444efef639632bf91.tar.xz
whirl-976ac6e5690449e9dcda954444efef639632bf91.zip
refactor(cli): restructure subcommand matching, removes shell completions subcommand
-rw-r--r--crates/whirl/src/cli.rs62
1 files changed, 21 insertions, 41 deletions
diff --git a/crates/whirl/src/cli.rs b/crates/whirl/src/cli.rs
index 861fb13..52a1858 100644
--- a/crates/whirl/src/cli.rs
+++ b/crates/whirl/src/cli.rs
@@ -1,7 +1,7 @@
// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only
-use structopt::clap::{App, AppSettings, Arg, ArgMatches, Shell, SubCommand};
+use structopt::clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
use whirl_config::Config;
use crate::subs::run;
@@ -25,37 +25,27 @@ impl Cli {
trace!("trace");
}
- if matches.is_present("run") {
- run().await;
- } else if let Some(cmd) = matches.subcommand_matches("config") {
- if cmd.is_present("show") {
- println!("{:#?}", Config::get());
- }
- } else if let Some(shell) = matches.subcommand_matches("completions") {
- if shell.is_present("powershell") {
- Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::PowerShell, ".");
- } else if shell.is_present("bash") {
- Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Bash, ".");
- } else if shell.is_present("elvish") {
- Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Elvish, ".");
- } else if shell.is_present("zsh") {
- Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Zsh, ".");
- } else if shell.is_present("fish") {
- Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Fish, ".");
- }
- debug!("generated shell completions");
- } else if matches.is_present("clean") {
- let cleanable_directories = vec!["log/"];
- for dir in cleanable_directories {
- let mut file_type = "directory";
- if !dir.ends_with('/') {
- file_type = "file";
- }
- println!("cleaning {}: {}", file_type, dir);
- if let Err(e) = std::fs::remove_dir_all(dir) {
- warn!("cannot delete {}: {}: {}", file_type, dir, e);
+ match matches.subcommand() {
+ ("run", _) => run().await,
+ ("config", Some(s_matches)) =>
+ match s_matches.subcommand() {
+ ("show", _) => println!("{:#?}", Config::get()),
+ _ => unreachable!(),
+ },
+ ("clean", _) => {
+ let cleanable_directories = vec!["log/"];
+ for dir in cleanable_directories {
+ let mut file_type = "directory";
+ if !dir.ends_with('/') {
+ file_type = "file";
+ }
+ info!("cleaning {}: {}", file_type, dir);
+ if let Err(e) = std::fs::remove_dir_all(dir) {
+ warn!("cannot delete {}: {}: {}", file_type, dir, e);
+ }
}
}
+ _ => unreachable!(),
}
Ok(())
@@ -72,18 +62,8 @@ impl Cli {
SubCommand::with_name("config")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommands(vec![SubCommand::with_name("show")]),
- SubCommand::with_name("completions")
- .setting(AppSettings::SubcommandRequiredElseHelp)
- .about("Generate shell completions")
- .subcommands(vec![
- SubCommand::with_name("powershell"),
- SubCommand::with_name("bash"),
- SubCommand::with_name("elvish"),
- SubCommand::with_name("zsh"),
- SubCommand::with_name("fish"),
- ]),
SubCommand::with_name("clean")
- .about("Delete Whirl generated files/ directories which are NOT critical. E.g., logs/"),
+ .about("Delete Whirl-generated files/ directories which are NOT critical. E.g., logs/"),
])
.args(&[
Arg::with_name("debug").short("d").long("debug"),