Skip to content

Commit

Permalink
doc: add run doc for debug-query and pattern strictness
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Jun 24, 2024
1 parent 347468c commit b6ba672
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion website/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sg run [OPTIONS] --pattern <PATTERN> [PATHS]...
| -p| --pattern `<PATTERN>` | AST pattern to match. |
| -r| --rewrite `<REWRITE>` | String to replace the matched AST node. |
| -l| --lang `<LANG>` | The language of the pattern query. ast-grep will infer the language based on file extension if this option is omitted. |
| | --debug-query | Print query pattern's tree-sitter AST. Requires lang be set explicitly. |
| | --debug-query`[=<format>]` | Print query pattern's tree-sitter AST. Requires lang be set explicitly. |
| -i| --interactive | Start interactive edit session. Code rewrite only happens inside a session. |
| -U| --update-all | Apply all rewrite without confirmation if true. |
| | --json`[=<style>]` | Output matches in structured JSON [possible values: pretty, stream, compact] |
Expand Down
57 changes: 38 additions & 19 deletions website/reference/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sg run [OPTIONS] --pattern <PATTERN> [PATHS]...

The paths to search. You can provide multiple paths separated by spaces

[default: .]
[default: `.`]


## Run Specific Options
Expand All @@ -36,9 +36,28 @@ String to replace the matched AST node

The language of the pattern. For full language list, visit https://ast-grep.github.io/reference/languages.html

### `--debug-query`
### `--debug-query[=<format>]`

Print query pattern's tree-sitter AST. Requires lang be set explicitly
Print query pattern's tree-sitter AST. Requires lang be set explicitly.

Possible values:
- **pattern**: Print the query parsed in Pattern format
- **ast**: Print the query in tree-sitter AST format, only named nodes are shown
- **cst**: Print the query in tree-sitter CST format, both named and unnamed nodes are shown
- **sexp**: Print the query in S-expression format

### `--strictness <STRICTNESS>`

The strictness of the pattern. More strict algorithm will match less code. See [match algorithm deep dive](/advanced/match-algorithm.html) for more details.

Possible values:
- **cst**: Match exact all node
- **smart**: Match all node except source trivial nodes
- **ast**: Match only ast nodes
- **relaxed**: Match ast node except comments
- **signature**: Match ast node except comments, without text

[default: smart]

## Input Options

Expand All @@ -49,12 +68,12 @@ Do not respect hidden file system or ignore files (.gitignore, .ignore, etc.).
You can suppress multiple ignore files by passing `no-ignore` multiple times.

Possible values:
- hidden: Search hidden files and directories. By default, hidden files and directories are skipped
- dot: Don't respect .ignore files. This does *not* affect whether ast-grep will ignore files and directories whose names begin with a dot. For that, use --no-ignore hidden
- exclude: Don't respect ignore files that are manually configured for the repository such as git's '.git/info/exclude'
- global: Don't respect ignore files that come from "global" sources such as git's `core.excludesFile` configuration option (which defaults to `$HOME/.config/git/ignore`)
- parent: Don't respect ignore files (.gitignore, .ignore, etc.) in parent directories
- vcs: Don't respect version control ignore files (.gitignore, etc.). This implies --no-ignore parent for VCS files. Note that .ignore files will continue to be respected
- **hidden**: Search hidden files and directories. By default, hidden files and directories are skipped
- **dot**: Don't respect .ignore files. This does *not* affect whether ast-grep will ignore files and directories whose names begin with a dot. For that, use --no-ignore hidden
- **exclude**: Don't respect ignore files that are manually configured for the repository such as git's '.git/info/exclude'
- **global**: Don't respect ignore files that come from "global" sources such as git's `core.excludesFile` configuration option (which defaults to `$HOME/.config/git/ignore`)
- **parent**: Don't respect ignore files (.gitignore, .ignore, etc.) in parent directories
- **vcs**: Don't respect version control ignore files (.gitignore, etc.). This implies --no-ignore parent for VCS files. Note that .ignore files will continue to be respected

### `--stdin`

Expand All @@ -80,9 +99,9 @@ Output matches in structured JSON .
If this flag is set, ast-grep will output matches in JSON format. You can pass optional value to this flag by using `--json=<style>` syntax to further control how JSON object is formatted and printed. ast-grep will `pretty`-print JSON if no value is passed. Note, the json flag must use `=` to specify its value. It conflicts with interactive.

Possible values:
- pretty: Prints the matches as a pretty-printed JSON array, with indentation and line breaks. This is useful for human readability, but not for parsing by other programs. This is the default value for the `--json` option
- stream: Prints each match as a separate JSON object, followed by a newline character. This is useful for streaming the output to other programs that can read one object per line
- compact: Prints the matches as a single-line JSON array, without any whitespace. This is useful for saving space and minimizing the output size
- **pretty**: Prints the matches as a pretty-printed JSON array, with indentation and line breaks. This is useful for human readability, but not for parsing by other programs. This is the default value for the `--json` option
- **stream**: Prints each match as a separate JSON object, followed by a newline character. This is useful for streaming the output to other programs that can read one object per line
- **compact**: Prints the matches as a single-line JSON array, without any whitespace. This is useful for saving space and minimizing the output size

### `--color <WHEN>`
Controls output color.
Expand All @@ -92,10 +111,10 @@ This flag controls when to use colors. The default setting is 'auto', which mean
[default: auto]

Possible values:
- auto: Try to use colors, but don't force the issue. If the output is piped to another program, or the console isn't available on Windows, or if TERM=dumb, or if `NO_COLOR` is defined, for example, then don't use colors
- always: Try very hard to emit colors. This includes emitting ANSI colors on Windows if the console API is unavailable (not implemented yet)
- ansi: Ansi is like Always, except it never tries to use anything other than emitting ANSI color codes
- never: Never emit colors
- **auto**: Try to use colors, but don't force the issue. If the output is piped to another program, or the console isn't available on Windows, or if TERM=dumb, or if `NO_COLOR` is defined, for example, then don't use colors
- **always**: Try very hard to emit colors. This includes emitting ANSI colors on Windows if the console API is unavailable (not implemented yet)
- **ansi**: Ansi is like Always, except it never tries to use anything other than emitting ANSI color codes
- **never**: Never emit colors

### `--heading <WHEN>`

Expand All @@ -106,9 +125,9 @@ If heading is used, the file name will be printed as heading before all matches
[default: auto]

Possible values:
- auto: Print heading for terminal tty but not for piped output
- always: Always print heading regardless of output type
- never: Never print heading regardless of output type
- **auto**: Print heading for terminal tty but not for piped output
- **always**: Always print heading regardless of output type
- **never**: Never print heading regardless of output type

## Context Options

Expand Down

0 comments on commit b6ba672

Please sign in to comment.