detect_type

Function detect_type 

Source
pub fn detect_type(value: &str) -> ArgumentType
Expand description

Detect argument type from string value

Tries to detect the most appropriate type for a string value.

§Detection Order

  1. Bool (true/false/yes/no/1/0/on/off)
  2. Integer (parseable as i64)
  3. Float (parseable as f64 and contains ‘.’)
  4. Path (starts with /, ./, ../, or contains )
  5. String (default)

§Example

assert_eq!(detect_type("42"), ArgumentType::Integer);
assert_eq!(detect_type("3.14"), ArgumentType::Float);
assert_eq!(detect_type("true"), ArgumentType::Bool);
assert_eq!(detect_type("/path/to/file"), ArgumentType::Path);
assert_eq!(detect_type("hello"), ArgumentType::String);