vx_cli/commands/
config.rs1use crate::ui::UI;
4use anyhow::Result;
5
6pub async fn handle() -> Result<()> {
7 UI::warning("Config command not yet implemented in new architecture");
8 UI::hint("Use .vx.toml files for project configuration");
9 Ok(())
10}
11
12pub async fn handle_init(tools: Vec<String>, template: Option<String>) -> Result<()> {
13 let spinner = UI::new_spinner("Initializing configuration...");
14
15 let config_content = if let Some(template) = template {
16 generate_template_config(&template, &tools)?
17 } else {
18 generate_default_config(&tools)?
19 };
20
21 std::fs::write(".vx.toml", config_content)?;
22 spinner.finish_and_clear();
23
24 UI::success("Initialized .vx.toml in current directory");
25 Ok(())
26}
27
28pub async fn handle_set(key: &str, value: &str) -> Result<()> {
29 UI::warning("Config set command not yet implemented in new architecture");
30 UI::hint(&format!("Would set {} = {}", key, value));
31 Ok(())
32}
33
34pub async fn handle_get(key: &str) -> Result<()> {
35 UI::warning("Config get command not yet implemented in new architecture");
36 UI::hint(&format!("Would get {}", key));
37 Ok(())
38}
39
40pub async fn handle_reset(key: Option<String>) -> Result<()> {
41 UI::warning("Config reset command not yet implemented in new architecture");
42 if let Some(key) = key {
43 UI::hint(&format!("Would reset {}", key));
44 } else {
45 UI::hint("Would reset all configuration");
46 }
47 Ok(())
48}
49
50pub async fn handle_edit() -> Result<()> {
51 UI::warning("Config edit command not yet implemented in new architecture");
52 UI::hint("Manually edit .vx.toml files for now");
53 Ok(())
54}
55
56fn generate_default_config(tools: &[String]) -> Result<String> {
57 let mut config = String::from("# vx configuration file\n");
58 config.push_str("# This file configures tool versions for this project\n\n");
59
60 if tools.is_empty() {
61 config.push_str("[tools.uv]\nversion = \"latest\"\n\n");
62 config.push_str("[tools.node]\nversion = \"lts\"\n");
63 } else {
64 for tool in tools {
65 config.push_str(&format!("[tools.{tool}]\nversion = \"latest\"\n\n"));
66 }
67 }
68
69 Ok(config)
70}
71
72fn generate_template_config(template: &str, additional_tools: &[String]) -> Result<String> {
75 let mut config = String::from("# vx configuration file\n");
76 config.push_str(&format!("# Generated from {template} template\n\n"));
77
78 match template {
79 "node" | "javascript" | "js" => {
80 config.push_str("[tools.node]\nversion = \"lts\"\n\n");
81 config.push_str("[tools.npm]\nversion = \"latest\"\n\n");
82 }
83 "python" | "py" => {
84 config.push_str("[tools.uv]\nversion = \"latest\"\n\n");
85 config.push_str("[tools.python]\nversion = \"3.11\"\n\n");
86 }
87 "rust" => {
88 config.push_str("[tools.rust]\nversion = \"stable\"\n\n");
89 config.push_str("[tools.cargo]\nversion = \"latest\"\n\n");
90 }
91 "go" => {
92 config.push_str("[tools.go]\nversion = \"latest\"\n\n");
93 }
94 _ => {
95 return Err(anyhow::anyhow!("Unknown template: {}", template));
96 }
97 }
98
99 for tool in additional_tools {
100 config.push_str(&format!("[tools.{tool}]\nversion = \"latest\"\n\n"));
101 }
102
103 Ok(config)
104}