Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub enum Commands {
Impact(ImpactArgs),
/// Show a de-noised overview of a repository tree
Overview(OverviewArgs),
/// Search for nodes by name, content, or type
Search(SearchArgs),
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -225,6 +227,49 @@ pub struct OverviewArgs {
pub changed: bool,
}

#[derive(Debug, Args)]
pub struct SearchArgs {
/// Search query (supports multiple space-separated terms)
#[arg(value_name = "QUERY")]
pub query: String,

/// Only search nodes of these types, comma-separated (e.g. Function,Endpoint)
#[arg(long, value_delimiter = ',')]
pub r#type: Vec<String>,

/// Only search within files whose path contains this fragment
#[arg(long)]
pub file: Option<String>,

/// Maximum number of results (default: 20)
#[arg(long, default_value = "20")]
pub limit: usize,

/// Also search inside function bodies and doc comments
#[arg(long, action = ArgAction::SetTrue)]
pub body: bool,

/// Show full source body for each result
#[arg(long, action = ArgAction::SetTrue)]
pub code: bool,

/// Show immediate callers and callees for each result
#[arg(long, action = ArgAction::SetTrue)]
pub context: bool,

/// Show associated test nodes for each result
#[arg(long, action = ArgAction::SetTrue)]
pub tests: bool,

/// Show sibling nodes in the same file for each result
#[arg(long, action = ArgAction::SetTrue)]
pub related: bool,

/// Files or directories to search
#[arg(value_name = "FILE_OR_DIR", num_args = 1..)]
pub files: Vec<String>,
}

impl CliArgs {
pub fn parse_and_expand() -> Result<Self> {
let mut args = Self::parse();
Expand Down Expand Up @@ -268,6 +313,11 @@ impl CliArgs {
if let Some(Commands::Overview(_)) = &args.command {
return Ok(args);
}

if let Some(Commands::Search(_)) = &args.command {
return Ok(args);
}

Ok(args)
}
}
5 changes: 5 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod overview;
mod parse;
mod progress;
mod render;
mod search;
mod summarize;
mod utils;

Expand Down Expand Up @@ -58,6 +59,7 @@ fn command_name(cli: &CliArgs) -> &'static str {
Some(Commands::Deps(_)) => "deps",
Some(Commands::Impact(_)) => "impact",
Some(Commands::Overview(_)) => "overview",
Some(Commands::Search(_)) => "search",
None => "parse",
}
}
Expand Down Expand Up @@ -116,6 +118,9 @@ async fn run(cli: CliArgs) -> Result<()> {
Some(Commands::Overview(args)) => {
overview::run(args, &mut Output::new(), output_mode)
}
Some(Commands::Search(args)) => {
search::run(args, &mut Output::new(), cli.verbose || cli.perf, output_mode).await
}
None => parse::run(&cli, &mut Output::new(), output_mode).await,
}
}
2 changes: 1 addition & 1 deletion cli/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn get_language_delimiter(file: &str) -> &'static str {
}
}

fn style_for_node_type(node_type: &NodeType) -> Style {
pub(crate) fn style_for_node_type(node_type: &NodeType) -> Style {
match node_type {
NodeType::Function => Style::new().green().bold(),
NodeType::Endpoint => Style::new().yellow().bold(),
Expand Down
Loading
Loading