use clap::{Parser, Subcommand, ValueEnum};
const AFTER_HELP: &str = "\
EXAMPLES:
# Check whether a repo is indexed before spending tokens
dwiki check tokio-rs/tokio
# List all available wiki topics
dwiki read tokio-rs/tokio
# Read a specific topic
dwiki read tokio-rs/tokio \"Runtime\"
# Ask a free-form question (AI-powered)
dwiki ask tokio-rs/tokio \"How does the scheduler work?\"
# Search the docs for a keyword
dwiki search tokio-rs/tokio \"spawn_blocking\"
# Machine-readable JSON output (recommended for agents)
dwiki check tokio-rs/tokio --output json
dwiki ask tokio-rs/tokio \"What is a JoinHandle?\" --output json
# Private repo via Devin endpoint
dwiki --url https://mcp.devin.ai/mcp --token $TOKEN ask myorg/repo \"...\"
ENVIRONMENT:
DEEPWIKI_URL Override MCP server URL (default: https://mcp.deepwiki.com/mcp)
DEEPWIKI_TOKEN Bearer token for private-repo endpoints
DISCLAIMER:
dwiki is an unofficial, third-party tool and is not affiliated with or
endorsed by DeepWiki or Cognition AI. Use at your own risk.";
#[derive(Parser)]
#[command(
name = "dwiki",
about = "Unofficial CLI for the DeepWiki MCP server",
long_about = "\
dwiki is an unofficial CLI tool that wraps the DeepWiki MCP server \
(https://mcp.deepwiki.com). It is designed for use inside coding agents \
and developer toolchains that need programmatic access to repository \
documentation.\n\
\n\
It exposes three DeepWiki MCP tools as subcommands:\n\
read_wiki_structure → dwiki read <repo>\n\
read_wiki_contents → dwiki read <repo> <topic>\n\
ask_question → dwiki ask <repo> <question>\n\
\n\
The `search` subcommand is a convenience wrapper around ask_question.\n\
The `check` subcommand performs an HTTP GET to https://deepwiki.com/<repo>\n\
to verify index status before making MCP calls.\n\
\n\
This tool is NOT affiliated with DeepWiki or Cognition AI.",
version,
after_help = AFTER_HELP
)]
pub struct Cli {
#[arg(
long,
global = true,
env = "DEEPWIKI_URL",
default_value = "https://mcp.deepwiki.com/mcp",
value_name = "URL"
)]
pub url: String,
#[arg(
long,
global = true,
env = "DEEPWIKI_TOKEN",
value_name = "TOKEN"
)]
pub token: Option<String>,
#[arg(
long,
global = true,
default_value = "text",
value_enum,
value_name = "FORMAT"
)]
pub output: OutputFormat,
#[arg(
long,
global = true,
default_value = "30",
value_name = "SECONDS"
)]
pub timeout: u64,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
Ask {
#[arg(value_name = "OWNER/REPO")]
repo: String,
#[arg(value_name = "QUESTION")]
question: String,
},
Read {
#[arg(value_name = "OWNER/REPO")]
repo: String,
#[arg(value_name = "TOPIC")]
topic: Option<String>,
},
Check {
#[arg(value_name = "OWNER/REPO")]
repo: String,
},
Search {
#[arg(value_name = "OWNER/REPO")]
repo: String,
#[arg(value_name = "QUERY")]
query: String,
},
}
#[derive(Clone, ValueEnum, Debug, PartialEq)]
pub enum OutputFormat {
Text,
Json,
}