Open HerringtonDarkholme opened 1 year ago
I have an idea like this:
sg run
will have a new option -f --filter
to filter match results based on the metavariable.
The filter will have three forms:
-f META_VAR=pattern
will match the meta-variable against ast-grep pattern pattern
.-f META_VAR/regexp/
will match the meta-variable against regular expression regexp
.-f META_VAR:kind_id
will match the meta-varaible with nodes of the syntax kind kind
.This is a mini-syntax to keep in sync with constraints
in the YAML format. Maybe it is too hard to learn and even harder to search on web.
Please leave comments here if you have any feedback! It can be a simple "love it"/"hate it". Or a lengthy paragraph explaining your preference. Of course I welcome your proposal!
Alternative design:
--filter-pattern META_VAR=pattern
--filter-regex META_VAR=regex
--filter-kind META_VAR=kind
which one is better?
I would definitely prefer the second design.
As a sometime / irregular user of ast-grep, I'm far less likely to recall the former syntax (e.g. -f META_VAR:kind_id
etc.).
The second/alternative design would probably lend itself more to ergonomic/easily-grokked shell completions?
Related: https://github.com/ast-grep/ast-grep/discussions/378
We can only use one single pattern to search code for command line
sg run
. This is convenient but less powerful tosg scan
. For example, if users want to finduserCol.update
oritemCol.update
, a single pattern$COL.update
cannot be done on command line. The work around is to write a temporary rule in YAML and usesg scan -r temp.yml
to scan code base.We can build a better CLI option to accept regular expression for meta-variables on command line.