claude_code_toolkit/traits/
setup.rs

1//! Setup and configuration wizard traits
2
3use crate::error::Result;
4use crate::types::Config;
5use async_trait::async_trait;
6use std::collections::HashMap;
7
8/// Context for setup wizard steps
9#[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/// Individual setup step
48#[async_trait]
49pub trait SetupStep: Send + Sync {
50  /// Get step identifier
51  fn step_id(&self) -> &str;
52
53  /// Get step description
54  fn description(&self) -> &str;
55
56  /// Check if step can be skipped
57  fn can_skip(&self, _context: &SetupContext) -> bool {
58    false
59  }
60
61  /// Check if step prerequisites are met
62  async fn check_prerequisites(&self, context: &SetupContext) -> Result<bool>;
63
64  /// Execute the setup step
65  async fn execute(&self, context: &mut SetupContext) -> Result<()>;
66
67  /// Validate step results
68  async fn validate(&self, context: &SetupContext) -> Result<bool>;
69
70  /// Get next step recommendations
71  fn next_steps(&self, _context: &SetupContext) -> Vec<String> {
72    Vec::new()
73  }
74}
75
76/// Setup wizard orchestrator
77#[async_trait]
78pub trait SetupWizard: Send + Sync {
79  /// Get wizard name
80  fn wizard_name(&self) -> &str;
81
82  /// Get all setup steps
83  fn get_steps(&self) -> Vec<Box<dyn SetupStep>>;
84
85  /// Run complete setup wizard
86  async fn run_setup(&self) -> Result<Config>;
87
88  /// Run specific steps
89  async fn run_steps(&self, step_ids: &[&str]) -> Result<Config>;
90
91  /// Get setup progress
92  fn get_progress(&self, context: &SetupContext) -> f32;
93
94  /// Handle setup errors
95  async fn handle_error(
96    &self,
97    step: &dyn SetupStep,
98    error: &crate::error::ClaudeCodeError,
99    context: &mut SetupContext
100  ) -> Result<bool>;
101}