1use crate::imports::*;
2use workflow_core::enums::Describe;
3
4pub trait Action<Context>: Describe + Clone + Copy + Eq {
5 type Error;
6
7 fn select() -> std::result::Result<Self, std::io::Error> {
8 Self::select_with_prompt(Self::caption())
9 }
10
11 fn select_with_prompt<S>(prompt: S) -> std::result::Result<Self, std::io::Error>
12 where
13 S: Display,
14 {
15 let mut selector = cliclack::select(prompt.to_string());
16 for action in Self::iter() {
17 selector = selector.item(*action, action.describe(), action.rustdoc());
18 }
19
20 selector.interact()
21 }
22
23 fn multiselect<S>(values: Vec<Self>) -> std::result::Result<Vec<Self>, std::io::Error> {
24 Self::multiselect_with_prompt(Self::caption(), values)
25 }
26
27 fn multiselect_with_prompt<S>(
28 prompt: S,
29 values: Vec<Self>,
30 ) -> std::result::Result<Vec<Self>, std::io::Error>
31 where
32 S: Display,
33 {
34 let mut selector = cliclack::multiselect(prompt.to_string()).initial_values(values);
35 for option in Self::into_iter() {
36 selector = selector.item(option, option.describe(), option.rustdoc());
37 }
38
39 selector.interact()
40 }
41
42 fn run(&self, _ctx: &mut Context) -> std::result::Result<(), Self::Error>;
43}