summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOrhun Parmaksız <orhunparmaksiz@gmail.com>2022-09-30 12:14:43 +0200
committerOrhun Parmaksız <orhunparmaksiz@gmail.com>2022-09-30 12:14:43 +0200
commit6685bd255c9d3388d57547526d2c148e44d67164 (patch)
tree98a1499aba29de6cc463df380e2ecbe858e8bdbc
parent9b0c09149efcc17b8f5d7974fe627e511cd0fb9b (diff)
refactor: Move command-line arguments to its own module
-rw-r--r--src/args.rs97
-rw-r--r--src/lib.rs1
-rw-r--r--src/main.rs4
-rw-r--r--src/util.rs98
4 files changed, 100 insertions, 100 deletions
diff --git a/src/args.rs b/src/args.rs
new file mode 100644
index 0000000..05aa740
--- /dev/null
+++ b/src/args.rs
@@ -0,0 +1,97 @@
+use clap::{Arg, ArgAction, Command as App};
+
+/* ASCII format of the project logo */
+const ASCII_LOGO: &str = "
+ `` ```````````` ```` ``````````` ```````````
+:NNs `hNNNNNNNNNNNNh` sNNNy yNNNNNNNNNN+ dNNNNNNNNNN:
+/MMMydMMyyyyyyydMMMMdhMMMMy yMMMyyyhMMMo dMMMyyydMMM/
+/MMMMMMM` oMMMMMMMMMMy yMMM` -MMMo dMMN /MMM/
+/MMMs:::hhhs oMMM+:::MMMNhhhNMMMdhhdMMMmhhhNMMN /MMM/
+:mmm/ dmmh +mmm- `mmmmmmmmmmmmmmmmmmmmmmmmmd /mmm:
+ ``` ``` ``` `````````````````````````` ```";
+
+/**
+ * Parse command line arguments using clap.
+ *
+ * @return App
+ */
+pub fn get_args() -> App {
+ App::new(env!("CARGO_PKG_NAME"))
+ .version(env!("CARGO_PKG_VERSION"))
+ .author(env!("CARGO_PKG_AUTHORS"))
+ .about(format!(
+ "{} {}\n{}\n{}\n\n{}",
+ env!("CARGO_PKG_NAME"),
+ env!("CARGO_PKG_VERSION"),
+ env!("CARGO_PKG_AUTHORS"),
+ env!("CARGO_PKG_DESCRIPTION"),
+ "Press '?' while running the terminal UI to see key bindings."
+ ))
+ .before_help(ASCII_LOGO)
+ .arg(
+ Arg::new("accent-color")
+ .short('a')
+ .long("accent-color")
+ .value_name("COLOR")
+ .default_value("white")
+ .help("Set the accent color using hex or color name")
+ .num_args(1),
+ )
+ .arg(
+ Arg::new("color")
+ .short('c')
+ .long("color")
+ .value_name("COLOR")
+ .default_value("darkgray")
+ .help("Set the main color using hex or color name")
+ .num_args(1),
+ )
+ .arg(
+ Arg::new("rate")
+ .short('t')
+ .long("tickrate")
+ .value_name("MS")
+ .default_value("250")
+ .help("Set the refresh rate of the terminal")
+ .num_args(1),
+ )
+ .arg(
+ Arg::new("reverse")
+ .short('r')
+ .long("reverse")
+ .help("Reverse the kernel module list")
+ .action(ArgAction::SetTrue),
+ )
+ .arg(
+ Arg::new("unicode")
+ .short('u')
+ .long("unicode")
+ .help("Show Unicode symbols for the block titles")
+ .action(ArgAction::SetTrue),
+ )
+ .subcommand(
+ App::new("sort")
+ .about("Sort kernel modules")
+ .arg(
+ Arg::new("size")
+ .short('s')
+ .long("size")
+ .help("Sort modules by their sizes")
+ .action(ArgAction::SetTrue),
+ )
+ .arg(
+ Arg::new("name")
+ .short('n')
+ .long("name")
+ .help("Sort modules by their names")
+ .action(ArgAction::SetTrue),
+ )
+ .arg(
+ Arg::new("dependent")
+ .short('d')
+ .long("dependent")
+ .help("Sort modules by their dependent modules")
+ .action(ArgAction::SetTrue),
+ ),
+ )
+}
diff --git a/src/lib.rs b/src/lib.rs
index a72f234..0722ee0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,6 +6,7 @@ pub mod kernel;
pub mod widgets;
#[macro_use]
pub mod util;
+pub mod args;
pub mod style;
use crate::app::{App, Block, InputMode, ScrollDirection};
diff --git a/src/main.rs b/src/main.rs
index 5326370..7ea8d72 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
+use kmon::args;
use kmon::event::Events;
use kmon::kernel::Kernel;
-use kmon::util;
use std::error::Error;
use std::io::stdout;
use termion::input::MouseTerminal;
@@ -15,7 +15,7 @@ use tui::Terminal;
* @return Result
*/
fn main() -> Result<(), Box<dyn Error>> {
- let args = util::parse_args();
+ let args = args::get_args().get_matches();
let kernel = Kernel::new(&args);
let events = Events::new(
args.get_one::<String>("rate")
diff --git a/src/util.rs b/src/util.rs
index 57efad3..a1c0268 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,4 +1,3 @@
-use clap::{Arg, ArgAction, ArgMatches, Command as App};
use std::process::Command;
/* Macro for concise initialization of hashmap */
@@ -37,103 +36,6 @@ pub const KEY_BINDINGS: &[(&str, &str)] = &[
("q, ctrl-c/d, esc", "quit"),
];
-/* ASCII format of the project logo */
-const ASCII_LOGO: &str = "
- `` ```````````` ```` ``````````` ```````````
-:NNs `hNNNNNNNNNNNNh` sNNNy yNNNNNNNNNN+ dNNNNNNNNNN:
-/MMMydMMyyyyyyydMMMMdhMMMMy yMMMyyyhMMMo dMMMyyydMMM/
-/MMMMMMM` oMMMMMMMMMMy yMMM` -MMMo dMMN /MMM/
-/MMMs:::hhhs oMMM+:::MMMNhhhNMMMdhhdMMMmhhhNMMN /MMM/
-:mmm/ dmmh +mmm- `mmmmmmmmmmmmmmmmmmmmmmmmmd /mmm:
- ``` ``` ``` `````````````````````````` ```";
-
-/**
- * Parse command line arguments using clap.
- *
- * @return ArgMatches
- */
-pub fn parse_args() -> ArgMatches {
- App::new(env!("CARGO_PKG_NAME"))
- .version(env!("CARGO_PKG_VERSION"))
- .author(env!("CARGO_PKG_AUTHORS"))
- .about(format!(
- "{} {}\n{}\n{}\n\n{}",
- env!("CARGO_PKG_NAME"),
- env!("CARGO_PKG_VERSION"),
- env!("CARGO_PKG_AUTHORS"),
- env!("CARGO_PKG_DESCRIPTION"),
- "Press '?' while running the terminal UI to see key bindings."
- ))
- .before_help(ASCII_LOGO)
- .arg(
- Arg::new("accent-color")
- .short('a')
- .long("accent-color")
- .value_name("COLOR")
- .default_value("white")
- .help("Set the accent color using hex or color name")
- .num_args(1),
- )
- .arg(
- Arg::new("color")
- .short('c')
- .long("color")
- .value_name("COLOR")
- .default_value("darkgray")
- .help("Set the main color using hex or color name")
- .num_args(1),
- )
- .arg(
- Arg::new("rate")
- .short('t')
- .long("tickrate")
- .value_name("MS")
- .default_value("250")
- .help("Set the refresh rate of the terminal")
- .num_args(1),
- )
- .arg(
- Arg::new("reverse")
- .short('r')
- .long("reverse")
- .help("Reverse the kernel module list")
- .action(ArgAction::SetTrue),
- )
- .arg(
- Arg::new("unicode")
- .short('u')
- .long("unicode")
- .help("Show Unicode symbols for the block titles")
- .action(ArgAction::SetTrue),
- )
- .subcommand(
- App::new("sort")
- .about("Sort kernel modules")
- .arg(
- Arg::new("size")
- .short('s')
- .long("size")
- .help("Sort modules by their sizes")
- .action(ArgAction::SetTrue),
- )
- .arg(
- Arg::new("name")
- .short('n')
- .long("name")
- .help("Sort modules by their names")
- .action(ArgAction::SetTrue),
- )
- .arg(
- Arg::new("dependent")
- .short('d')
- .long("dependent")
- .help("Sort modules by their dependent modules")
- .action(ArgAction::SetTrue),
- ),
- )
- .get_matches()
-}
-
/**
* Execute a operating system command and return its output.
*