This information is available in shortened form with grasp --help, or in full verbose form with grasp --help verbose. You can see an individual option's verbose help with grasp --option-name.


-h, --help

--help displays help for options

-h may be used at any time in place of --help

--help more displays this help

--help --option-name displays further help for that option

for example: --help --help would display this information

--help verbose displays the same help as --help --option-name, but for all options

--help syntax displays information about JavaScript’s syntax

--help node-name displays further information about a JavaScript node

for example: --help if displays more information about an if statement

--help categories displays information about node type categories

--help category-name displays further information about a node type category

--help advanced displays help for all options, including those hidden by default Everything after this option is considered a positional argument, even if it looks like an option.

  • --help
  • --help --replace
  • --help -R
  • --help syntax

-v, --version

Print version information and exit.

-d, --debug

Output debug information.

-x, --extensions [String]

A comma separated list of acceptable file extensions. Use a dot . for any extension.

  • --extensions js,json
  • --extensions .

-r, --recursive

Recursively search directories. If files or paths are left out, then . is assumed.

-p, --parser (path::String, options::Maybe Object)

Sets the parser and options for the parser. Argument value is a tuple, with the first item being the require path, and the second an optional object with options for the parser when calling its parse function.

(acorn, {locations: true, ecmaVersion: 6, sourceType: 'module', allowHashBang: true})
  • --parser "(./path/to/esprima, {loc: true})"


-R, --replace replacement::String

Each node that is matched will be replaced with the text that you input. There are a couple of special cases:

The text {{}} will be replaced with the source of the matched node.

{{selector}} will be replaced with the first result of querying the matched node with the selector. If you used equery to get the results, then the replacement selector will be parsed as equery.

Since positional arguments may appear anywhere, you can place the --replace replacement after the selector if you wish, eg. selector --replace replacement file.js.

By default, the result of using --replace will be to print out the results - if you wish to create new file(s) you can check out the --to option, or if you wish to edit the input file(s) in place, take a look at the --in-place option.

  • --replace foo
  • --replace 'f()'
  • --replace 'while () {\n;\n}'

-F, --replace-file file::String

Replace each match with contents of file.

  • --replace-file path/to/file

--replace-func Function

Use function instead of string pattern when using as library.

-t, --to Object | String

If an object, the keys are the paths to the input files, and the values are the corresponding output paths.

If a string, then the output is written to the path specified. The special character % is expanded to the current input file’s filename.

  • --to "{input.js: output.js, path/to/input2.js: path/to/output2.js}"
  • --to "output/%.js"

-i, --in-place

Overwrite input files with replaced output.

Selector interpretation

-g, --engine path::String

The require path for the query engine. The query engine must have parse(selector) -> parsedSelector, queryParsed(parsedSelector, ast) -> results, and query(selector, ast) -> results functions exposed.

  • --engine path/to/engine

-s, --squery

Use squery - selector query - css style selectors.

-e, --equery

Use equery - example query - instead of the default squery. Use by typing in an example of the code you want (formatting is irrelevant), with optional wildcards. It is less powerful, but may be easier to use for simpler tasks, than squery. For more information, use --help equery.

-f, --file file::String

Obtain selector from file.

  • --file path/to/selector-file

Output control

-m, --max-count n::Int

Stop after n matches.

  • --max-count 2

-n, --line-number

Print line number with output lines.


-b, --col-number

Print column number with output lines.

-H, --filename

Print the file name for each match (opposite: --no-filename).

-o, --only-matching

Show only the matching part of the line(s).

-q, --quiet, --silent

Suppress all normal output.

-W, --files-without-match

Print only names of files containing no match.

-w, --files-with-matches

Print only names of files containing matches.

-c, --count

Print only a count of matches per file.

-O, --color, --colour

Use color to highlight matches.


-j, --json

Prints out JSON for the output instead of formatted results. This will print out the node data as JSON, instead of the formatted text.

Context control

-B, --before-context n::Int

Print n lines of leading context.

  • --before-context 3
  • -B 3

-A, --after-context n::Int

Print n lines of trailing context.

  • --after-context 2
  • -A 2

-C, --context n::Int

Print n lines of output context.

  • --context 1
  • -C 1


Same as –context NUM.

  • -3