cli_get_option

Function cli_get_option 

Source
pub fn cli_get_option<K, V>(question: &str, options: &IndexMap<K, V>) -> K
where K: Display + Eq + PartialEq + Hash + FromStr, <K as FromStr>::Err: Display, V: Display,
Expand description

Prompts the user to select an option from a list.

Displays a question and list of options, then waits for the user to select one. The function will continue prompting until a valid option is selected.

§Arguments

  • question - The question or prompt to display
  • options - An IndexMap of options where keys are option identifiers and values are descriptions

§Returns

Returns the key of the selected option.

§Example

use falcon_cli::{cli_get_option, indexmap};
use indexmap::IndexMap;

let options = indexmap! {
    1 => "First option",
    2 => "Second option",
    3 => "Third option",
};

let selected = cli_get_option("Which option do you prefer?", &options);
println!("You selected: {}", selected);