use clap::Args;
use octocode::store::Store;
#[derive(Args, Debug)]
pub struct ClearArgs {
#[arg(long, default_value = "all")]
pub mode: String,
}
pub async fn execute(store: &Store, args: &ClearArgs) -> Result<(), anyhow::Error> {
match args.mode.as_str() {
"all" => {
println!("Clearing all database tables...");
store.clear_all_tables().await?;
println!("Successfully dropped all tables and schemas.");
println!(
"Note: Tables will be recreated with current schema on next indexing operation."
);
}
"code" => {
println!("Clearing code blocks table...");
store.clear_code_table().await?;
store.clear_git_metadata().await?;
println!("Successfully cleared code blocks table and git metadata.");
println!("Note: Code content will be re-indexed on next indexing operation.");
}
"docs" => {
println!("Clearing document blocks table...");
store.clear_docs_table().await?;
store.clear_git_metadata().await?;
println!("Successfully cleared document blocks table and git metadata.");
println!("Note: Documentation content will be re-indexed on next indexing operation.");
}
"text" => {
println!("Clearing text blocks table...");
store.clear_text_table().await?;
store.clear_git_metadata().await?;
println!("Successfully cleared text blocks table and git metadata.");
println!("Note: Text content will be re-indexed on next indexing operation.");
}
"commits" => {
println!("Clearing commit blocks table...");
store.clear_commits_table().await?;
store.clear_commits_git_metadata().await?;
println!("Successfully cleared commit blocks table and commits git metadata.");
println!("Note: Commits will be re-indexed on next indexing operation.");
}
"graphrag" => {
println!("Clearing GraphRAG tables...");
store.clear_graph_nodes().await?;
store.clear_graph_relationships().await?;
store.clear_graphrag_git_metadata().await?;
println!("Successfully cleared GraphRAG nodes, relationships, and git metadata.");
println!("Note: GraphRAG will be rebuilt on next indexing operation.");
}
_ => {
return Err(anyhow::anyhow!(
"Invalid mode '{}'. Valid modes are: all, code, docs, text, commits, graphrag",
args.mode
));
}
}
Ok(())
}