#flags #args #give #detect #prefix #flag-detect #static-flag

bin+lib args_flags_1

A library for manipulating with flags

3 unstable releases

0.2.0 Jan 8, 2023
0.1.1 Jan 2, 2023
0.1.0 Nov 25, 2022

#14 in #give

MIT license

8KB
104 lines

Args flags

This project is trying to simplify the process of making CLI program. it will detect flag for your program and give you ways to have access to list of Flag the program is receiving.

Example

imports:

use args_flags_1::{FlagDetect, StaticFlagOnly, StaticFlag, Flag};

use (one prefix):

let flags: Vec<Flag> = StaticFlag::get("-", std::env::args());

use of more than one prefix (Beta):

let flags: Vec<Flag> = StaticFlag::getn(vec!["--", "-"], std::env::args());

use static version

only flags:

let prefix: &str = "-";

let flags: Vec<String> = StaticFlag::get(prefix, std::env::args());
let flags: Vec<String> = StaticFlag::getn(vec![prefix], std::env::args());

flags:

let prefix: &str = "-";

let flags: Vec<Flag> = StaticFlag::get(prefix, std::env::args());
let flags: Vec<Flag> = StaticFlag::getn(vec![prefix], std::env::args());

use with struct (no static):

let prefix: &str = "-";
let args: std::env::Args = std::env::args();
let detect: FlagDetect = FlagDetect::new(prefix).from_args(args);

// gives back value of the flag
let s_flag: Option<String> = detect.find("-s");
match s_flag {
    Some(x) => {},
    None => {}
}

No runtime deps