NAME

Developer::Dashboard::CLI::OpenFileGrep - content-search adapter for d2 of

SYNOPSIS

use Developer::Dashboard::CLI::OpenFileGrep qw(grep_matching_files);
my @files = grep_matching_files( args => [ '-nr', 'needle', 'src' ] );

DESCRIPTION

Runs the system grep executable for the historical d2 of grep mode and returns the unique files containing matches. Arguments remain an array rather than shell text, so patterns and paths are passed literally to the child process. -H and -n are added to make output consistently identifiable when the search scope contains only one file.

On real Windows, when grep does not resolve, the system call cannot tell a missing binary from no match: Perl's system() falls back to cmd.exe, which reports the missing binary with exit 1, the same code grep uses for "no matches". In that one case the adapter settles the ambiguous exit code with a Perl-native content search that produces the same "file:line:content" output and flows through the same result decoding; everywhere grep resolves, the system executable runs untouched.

PURPOSE

This module adapts content grep results to the file chooser used by the d2 open-file command.

WHY IT EXISTS

Path-name regex search and content search are distinct operations. Keeping grep execution and result decoding here prevents the main open-file resolver from confusing `grep` options with path patterns and keeps process handling small and testable.

WHEN TO USE

Use this module when changing the `d2 of grep` content-search interface, grep process failure handling, or conversion of grep output into file matches. The Perl-native fallback lives here too: change it when the set of grep options it honours needs to grow, or when its output shape must stay identical to what the system executable produces. native_grep_usage() prints the usage text for that fallback; d2 of grep --help shows it when no system grep is installed.

HOW TO USE

Call grep_matching_files with the arguments following the grep token. It returns matching paths in first-seen order, returns an empty list for grep's normal no-match status, and reports execution errors or invalid grep arguments explicitly. The native fallback honours -r/-R, -i, -v, -w, -x, -F, -E, -e, -n, -H, -s, -q, -a, -I, -d and their long forms; any other option dies naming the flag rather than searching with the wrong meaning, and any file error dies naming the file, exactly as a system grep failure with exit 2 does.

WHAT USES IT

Developer::Dashboard::CLI::OpenFile dispatches the public d2 of grep form to this module, then sends the returned paths to the regular print or editor-selection flow.

EXAMPLES

my @recursive = grep_matching_files( args => [ '-nr', 'needle', 'lib' ] );
my @literal   = grep_matching_files( args => [ '-nr', '-F', 'a+b', 'lib' ] );