Skip to content

Commit 73b019b

Browse files
committed
feat: add command to add tools to config
- Add 'capsync add <tool>' command - Validates tool name against supported tools list - Shows error if tool doesn't exist or is unsupported - Automatically syncs after adding (unless --no-sync flag is used) - If tool already exists in config, just runs sync
1 parent d7d44c2 commit 73b019b

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

src/cli.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::config::{self, Config, DestinationConfig};
22
use crate::detect::ToolDetector;
33
use crate::sync::SyncManager;
4-
use crate::tools::all_tools;
4+
use crate::tools::{all_tools, get_tool};
55
use anyhow::{Result, anyhow};
66
use clap::{Parser, Subcommand};
77
use std::collections::HashMap;
@@ -26,6 +26,14 @@ pub enum Commands {
2626
DetectTools,
2727
/// Sync skills to all enabled tools
2828
Sync,
29+
/// Add a tool to configuration and sync
30+
Add {
31+
/// Tool name to add
32+
tool: String,
33+
/// Skip syncing after adding
34+
#[arg(long)]
35+
no_sync: bool,
36+
},
2937
/// Remove symlink from a tool (use --all to remove all)
3038
Remove {
3139
/// Tool name to remove symlink from (optional if --all is used)
@@ -46,6 +54,7 @@ pub fn run() -> Result<()> {
4654
Commands::Config => show_config(),
4755
Commands::DetectTools => detect_tools(),
4856
Commands::Sync => sync_skills(),
57+
Commands::Add { tool, no_sync } => add_tool(&tool, no_sync),
4958
Commands::Remove { tool, all } => {
5059
if all {
5160
remove_all()
@@ -203,6 +212,47 @@ fn remove_all() -> Result<()> {
203212
SyncManager::remove_all(&config)
204213
}
205214

215+
fn add_tool(tool_name: &str, no_sync: bool) -> Result<()> {
216+
let mut config = config::load_config()?;
217+
218+
// Validate tool exists
219+
let tool = get_tool(tool_name).ok_or_else(|| {
220+
anyhow!(
221+
"Tool '{}' does not exist or is unsupported in the current version",
222+
tool_name
223+
)
224+
})?;
225+
226+
// Check if already in config
227+
if config.destinations.contains_key(tool_name) {
228+
println!("Tool '{}' is already in the configuration", tool_name);
229+
if !no_sync {
230+
println!("Running sync...");
231+
return sync_skills();
232+
}
233+
return Ok(());
234+
}
235+
236+
// Add tool to config
237+
config.destinations.insert(
238+
tool_name.to_string(),
239+
DestinationConfig {
240+
enabled: true,
241+
path: tool.skills_path,
242+
},
243+
);
244+
245+
config::save_config(&config)?;
246+
println!("Added '{}' to configuration", tool_name);
247+
248+
if !no_sync {
249+
println!("Running sync...");
250+
sync_skills()
251+
} else {
252+
Ok(())
253+
}
254+
}
255+
206256
fn show_status() -> Result<()> {
207257
let config = config::load_config()?;
208258

src/tools.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@ pub fn all_tools() -> Vec<Tool> {
5959
Tool::new("zencoder", ".zencoder", ".zencoder/skills"),
6060
]
6161
}
62+
63+
pub fn get_tool(name: &str) -> Option<Tool> {
64+
all_tools().into_iter().find(|t| t.name == name)
65+
}

0 commit comments

Comments
 (0)