Skip to content

Commit 45bffa7

Browse files
fix: udpate command name part 1
1 parent bef9280 commit 45bffa7

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

website/guide/tooling-overview.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
ast-grep's tooling supports multiple stages of your development. Here is a list of the tools and their purpose:
66

7-
* To run an ad-hoc query and apply rewrite: `sg run`.
8-
* Routinely check your codebase: `sg scan`.
9-
* Generate ast-grep's scaffolding files: `sg new`.
10-
* Develop new ast-grep rules and test them: `sg test`.
11-
* Start Language Server for editor integration: `sg lsp`.
7+
* To run an ad-hoc query and apply rewrite: `ast-grep run`.
8+
* Routinely check your codebase: `ast-grep scan`.
9+
* Generate ast-grep's scaffolding files: `ast-grep new`.
10+
* Develop new ast-grep rules and test them: `ast-grep test`.
11+
* Start Language Server for editor integration: `ast-grep lsp`.
1212

1313
We will walk through some important features that are common to these commands.
1414

@@ -26,7 +26,7 @@ Pressing `y` will accept the rewrite, `n` will skip it, `e` will open the file i
2626
Example:
2727

2828
```bash
29-
sg scan --interactive
29+
ast-grep scan --interactive
3030
```
3131

3232
## JSON Mode
@@ -36,7 +36,7 @@ Composability is a key perk of command line tooling. ast-grep is no exception.
3636
`--json` will output results in JSON format. This is useful to pipe the results to other tools. For example, you can use [jq](https://stedolan.github.io/jq/) to extract information from the results and render it in [jless](https://jless.io/).
3737

3838
```bash
39-
sg run -p 'Some($A)' -r 'None' --json | jq '.[].replacement' | jless
39+
ast-grep run -p 'Some($A)' -r 'None' --json | jq '.[].replacement' | jless
4040
```
4141

4242
The format of the JSON output is an array of match objects.
@@ -71,18 +71,18 @@ See [JSON mode doc](/guide/tools/json.html) for more detailed explanation and ex
7171
## Run One Single Query or One Single Rule
7272

7373
You can also use ast-grep to explore a proper pattern for your query. There are two ways to try your pattern or rule.
74-
For testing one pattern, you can use `sg run` command.
74+
For testing one pattern, you can use `ast-grep run` command.
7575

7676
```bash
77-
sg run -p 'YOUR_PATTERN' --debug-query
77+
ast-grep run -p 'YOUR_PATTERN' --debug-query
7878
```
7979

8080
The `--debug-query` option will output the tree-sitter ast of the query.
8181

82-
To test one single rule, you can use `sg scan -r`.
82+
To test one single rule, you can use `ast-grep scan -r`.
8383

8484
```bash
85-
sg scan -r path/to/your/rule.yml
85+
ast-grep scan -r path/to/your/rule.yml
8686
```
8787
It is useful to test one rule in isolation.
8888

@@ -94,11 +94,11 @@ You can use bash's [pipe operator](https://linuxhint.com/bash_pipe_tutorial/) `|
9494

9595
### Example: Simple Web Crawler
9696

97-
Let's see an example in action. Combining with `curl`, `ast-grep` and `jq`, we can build a [simple web crawler](https://twitter.com/trevmanz/status/1671572111582978049) on command line. The command below uses `curl` to fetch the HTML source of SciPy conference website, and then uses `sg` to parse and extract relevant information as JSON from source, and finally uses `jq` to transform our matching results.
97+
Let's see an example in action. Combining with `curl`, `ast-grep` and `jq`, we can build a [simple web crawler](https://twitter.com/trevmanz/status/1671572111582978049) on command line. The command below uses `curl` to fetch the HTML source of SciPy conference website, and then uses `ast-grep` to parse and extract relevant information as JSON from source, and finally uses `jq` to transform our matching results.
9898

9999
```bash
100100
curl -s https://schedule2021.scipy.org/2022/conference/ |
101-
sg -p '<div $$$> $$$ <i>$AUTHORS</i> </div>' --lang html --json --stdin |
101+
ast-grep -p '<div $$$> $$$ <i>$AUTHORS</i> </div>' --lang html --json --stdin |
102102
jq '
103103
.[]
104104
| .metaVariables
@@ -121,15 +121,15 @@ The command above will produce a list of authors from the SciPy 2022 conference
121121

122122
With this feature, even if your preferred language does not have native bindings for ast-grep, you can still parse code from standard input (StdIn) to use ast-grep programmatically from the command line.
123123

124-
You can invoke sg, the command-line interface for ast-grep, as a subprocess to search and replace code.
124+
You can invoke `ast-grep`, the command-line interface for ast-grep, as a subprocess to search and replace code.
125125

126126
### Caveats
127127

128128
**StdIn mode has several restrictions**, though:
129129

130130
* It conflicts with `--interactive` mode, which reads user responses from StdIn.
131-
* For the `run` command, you must specify the language of the StdIn code with `--lang` or `-l` flag. For example: `echo "print('Hello world')" | sg run --lang python`. This is because ast-grep cannot infer code language without file extension.
132-
* Similarly, you can only `scan` StdIn code against _one single rule_, specified by `--rule` or `-r` flag. The rule must match the language of the StdIn code. For example: `echo "print('Hello world')" | sg scan --rule "python-rule.yml"`
131+
* For the `run` command, you must specify the language of the StdIn code with `--lang` or `-l` flag. For example: `echo "print('Hello world')" | ast-grep run --lang python`. This is because ast-grep cannot infer code language without file extension.
132+
* Similarly, you can only `scan` StdIn code against _one single rule_, specified by `--rule` or `-r` flag. The rule must match the language of the StdIn code. For example: `echo "print('Hello world')" | ast-grep scan --rule "python-rule.yml"`
133133

134134
### Enable StdIn Mode
135135

@@ -155,7 +155,7 @@ ast-grep will hang there if you run it in a tty terminal session with `--stdin`
155155
Here is a bonus example to use [fzf](https://github.com/junegunn/fzf/blob/master/ADVANCED.md#using-fzf-as-interactive-ripgrep-launcher) as interactive ast-grep launcher.
156156

157157
```bash
158-
SG_PREFIX="sg run --color=always -p "
158+
SG_PREFIX="ast-grep run --color=always -p "
159159
INITIAL_QUERY="${*:-}"
160160
: | fzf --ansi --disabled --query "$INITIAL_QUERY" \
161161
--bind "start:reload:$SG_PREFIX {q}" \
@@ -172,12 +172,12 @@ See the [editor integration](/guide/tools/editors.md) doc page.
172172

173173
## Shell Completions
174174
ast-grep comes with shell autocompletion scripts. You can generate a shell script and eval it when your shell starts up.
175-
The script will enable you to smoothly complete `sg` command's options by `tab`bing.
175+
The script will enable you to smoothly complete `ast-grep` command's options by `tab`bing.
176176

177177
This command will instruct ast-grep to generate shell completion script:
178178

179179
```shell
180-
sg completions <SHELL>
180+
ast-grep completions <SHELL>
181181
```
182182

183183
`<SHELL>` is an optional argument and can be one of the `bash`, `elvish`, `fish`, `powershell` and `zsh`. If shell is not specified, ast-grep will infer the correct shell from environment variable like `$SHELL`.
@@ -189,7 +189,7 @@ The exact steps required to enable autocompletion will vary by shell. For instru
189189
If you are using zsh, add this line to your `~/.zshrc`.
190190

191191
```shell
192-
eval "$(sg completions)"
192+
eval "$(ast-grep completions)"
193193
```
194194

195195
<video src="https://github-production-user-asset-6210df.s3.amazonaws.com/38807139/260303710-ef8b969e-2eb5-4345-932a-be4093466a48.mp4" controls/>
@@ -200,7 +200,7 @@ If you want to automate [ast-grep linting](https://github.com/marketplace/action
200200

201201
For example, you can run ast-grep linting every time you push a new commit to your main branch.
202202

203-
To use ast-grep in GitHub Action, you need to [set up a project](/guide/scan-project.html) first. You can do this by running `sg new` in your terminal, which will guide you through the process of creating a configuration file and a rules file.
203+
To use ast-grep in GitHub Action, you need to [set up a project](/guide/scan-project.html) first. You can do this by running `ast-grep new` in your terminal, which will guide you through the process of creating a configuration file and a rules file.
204204

205205
Next, you need to create a workflow file for GitHub Action. This is a YAML file that defines the steps and actions that will be executed when a certain event occurs. You can create a workflow file named `ast-grep.yml` under the `.github/workflows/` folder in your repository, with the following content:
206206

@@ -219,7 +219,7 @@ jobs:
219219
```
220220
221221
This workflow file tells GitHub Action to run ast-grep linting on every push event, using the latest Ubuntu image and the official ast-grep action.
222-
The action will check out your code and run [`sg scan`](/reference/cli.html#sg-scan) on it, reporting any errors or warnings.
222+
The action will check out your code and run [`ast-grep scan`](/reference/cli.html#sg-scan) on it, reporting any errors or warnings.
223223

224224
That's it! You have successfully set up ast-grep linting in GitHub Action. Now, every time you push a new commit to your main branch, GitHub Action will automatically run ast-grep linting and show you the results. You can see an example of how it looks like below.
225225

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy