MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / choose

Function choose

crates/chat-cli/src/util/mod.rs:63–83  ·  view source on GitHub ↗
(prompt: impl Display, options: &[impl ToString])

Source from the content-addressed store, hash-verified

61}
62
63pub fn choose(prompt: impl Display, options: &[impl ToString]) -> Result<Option<usize>> {
64 if options.is_empty() {
65 bail!("no options passed to choose")
66 }
67
68 if !stdout().is_terminal() {
69 warn!("called choose while stdout is not a terminal");
70 return Ok(Some(0));
71 }
72
73 match Select::with_theme(&dialoguer_theme())
74 .items(options)
75 .default(0)
76 .with_prompt(prompt.to_string())
77 .interact_opt()
78 {
79 Ok(ok) => Ok(ok),
80 Err(dialoguer::Error::IO(io)) if io.kind() == ErrorKind::Interrupted => Ok(None),
81 Err(e) => Err(e).wrap_err("Failed to choose"),
82 }
83}
84
85pub fn input(prompt: &str, initial_text: Option<&str>) -> Result<String> {
86 if !stdout().is_terminal() {

Callers 1

executeMethod · 0.85

Calls 6

dialoguer_themeFunction · 0.85
to_stringMethod · 0.80
kindMethod · 0.80
is_emptyMethod · 0.45
defaultMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected