summaryrefslogtreecommitdiff
path: root/src/flags.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/flags.rs')
-rw-r--r--src/flags.rs32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/flags.rs b/src/flags.rs
index 9432b8f..c93f3ef 100644
--- a/src/flags.rs
+++ b/src/flags.rs
@@ -1,3 +1,9 @@
+
+const HELP_FLAG: &str = "help h";
+const VERSION_FLAG: &str = "version v";
+const DONT_PERSIST: &str = "d";
+
+
pub struct Flags {
pub help: bool,
pub version: bool,
@@ -5,6 +11,13 @@ pub struct Flags {
pub arg_count: usize
}
+
+/// Parses an list of String arguments into a set of flags that can be used by crab
+/// #### Arguments
+/// * `args` - The list of String arguments
+/// #### Returns
+/// * `None` - If there is an invalid argument in the list
+/// * `Some(Flags)` - If the arguments were secussfully parsed, returning the flags
pub fn parse(args: &[String]) -> Option<Flags> {
let mut flags = Flags {
help: false,
@@ -34,14 +47,20 @@ pub fn parse(args: &[String]) -> Option<Flags> {
Some(flags)
}
+
+/// Checks if a given string is a given argument
fn is_arg(arg: &str) -> bool {
return arg.starts_with("-");
}
-const HELP_FLAG: &str = "help h";
-const VERSION_FLAG: &str = "version v";
-const DONT_PERSIST: &str = "d";
+/// Sets a flag in a `Flags` struct
+/// #### Arguments
+/// * `arg` - The argument to check
+/// * `flags` - The `Flags` stuct to update
+/// #### Returns
+/// * `true` - If the argument passed is a valid flag
+/// * `false` - If the argument passed is not a valid flag
fn set_flag(arg: &str, flags: &mut Flags) -> bool {
if has_flag_set(&arg, HELP_FLAG) {
flags.help = true;
@@ -56,6 +75,13 @@ fn set_flag(arg: &str, flags: &mut Flags) -> bool {
false
}
+
+/// Returns if a given argument is a certain flag
+/// #### Arguments
+/// * `arg` - The arch to check
+/// #### Returns
+/// * `true` - If the argument matches the flag
+/// * `false` - If the argument doesn't match the flag
fn has_flag_set(arg: &str, check: &str) -> bool {
for check_arg in check.split(" ") {
if check_arg == arg {