octocode 0.14.1

AI-powered code intelligence with semantic search, knowledge graphs, and built-in MCP server. Transform your codebase into a queryable knowledge graph for AI assistants.
Documentation
// Copyright 2026 Muvon Un Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use clap::Args;
use octocode::store::Store;

#[derive(Args, Debug)]
pub struct ClearArgs {
	/// Clear mode: all (default), code, docs, text, commits, or graphrag
	#[arg(long, default_value = "all")]
	pub mode: String,
}

/// Clear database tables based on mode
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(())
}