claude_code_toolkit/traits/
setup.rs1use crate::error::Result;
4use crate::types::Config;
5use async_trait::async_trait;
6use std::collections::HashMap;
7
8#[derive(Debug, Default)]
10pub struct SetupContext {
11 pub config: Config,
12 pub user_input: HashMap<String, String>,
13 pub flags: HashMap<String, bool>,
14 pub step_results: HashMap<String, String>,
15}
16
17impl SetupContext {
18 pub fn new() -> Self {
19 Self::default()
20 }
21
22 pub fn set_input(&mut self, key: &str, value: &str) {
23 self.user_input.insert(key.to_string(), value.to_string());
24 }
25
26 pub fn get_input(&self, key: &str) -> Option<&String> {
27 self.user_input.get(key)
28 }
29
30 pub fn set_flag(&mut self, key: &str, value: bool) {
31 self.flags.insert(key.to_string(), value);
32 }
33
34 pub fn get_flag(&self, key: &str) -> bool {
35 self.flags.get(key).copied().unwrap_or(false)
36 }
37
38 pub fn set_result(&mut self, step: &str, result: &str) {
39 self.step_results.insert(step.to_string(), result.to_string());
40 }
41
42 pub fn get_result(&self, step: &str) -> Option<&String> {
43 self.step_results.get(step)
44 }
45}
46
47#[async_trait]
49pub trait SetupStep: Send + Sync {
50 fn step_id(&self) -> &str;
52
53 fn description(&self) -> &str;
55
56 fn can_skip(&self, _context: &SetupContext) -> bool {
58 false
59 }
60
61 async fn check_prerequisites(&self, context: &SetupContext) -> Result<bool>;
63
64 async fn execute(&self, context: &mut SetupContext) -> Result<()>;
66
67 async fn validate(&self, context: &SetupContext) -> Result<bool>;
69
70 fn next_steps(&self, _context: &SetupContext) -> Vec<String> {
72 Vec::new()
73 }
74}
75
76#[async_trait]
78pub trait SetupWizard: Send + Sync {
79 fn wizard_name(&self) -> &str;
81
82 fn get_steps(&self) -> Vec<Box<dyn SetupStep>>;
84
85 async fn run_setup(&self) -> Result<Config>;
87
88 async fn run_steps(&self, step_ids: &[&str]) -> Result<Config>;
90
91 fn get_progress(&self, context: &SetupContext) -> f32;
93
94 async fn handle_error(
96 &self,
97 step: &dyn SetupStep,
98 error: &crate::error::ClaudeCodeError,
99 context: &mut SetupContext
100 ) -> Result<bool>;
101}