CLI Quickstart

The Grit CLI is a command-line interface for Grit. It allows you to apply GritQL patterns and run custom workflows.

Installation

You can install the Grit CLI from NPM:

Terminal
npm install --location=global @getgrit/cli

Alternatively, you can also install Grit with an installation script:

Terminal
curl -fsSL https://docs.grit.io/install | bash

You can optionally run grit init to initialize a local Grit configuration and grit install to install additional binaries used for custom workflows.

Usage

Overview

The primary purpose of the Grit CLI is to apply automatic changes. For example, you can automatically upgrade React Class Components to hooks with the following command from our standard library:

Terminal
grit apply react_to_hooks

Applying patterns

Use grit apply to apply a pattern to the current directory including anything from our standard library and custom patterns written in GritQL.

Some examples include:

Terminal
grit apply "const" # Simply shows all const declarations
grit apply no_console_log # Removes console.log statements from JavaScript
grit apply ternary_op # Converts if-else statements to ternary operators in Python
grit apply cypress_to_playwright # Converts Cypress tests to Playwright tests

Parameters can be passed to some patterns as well:

Terminal
grit apply 'remove_import(from=`"react"`)' # Removes all import statements from React

To view the full list of available patterns in the standard library, run:

Terminal
grit list

Telemetry

We collect usage data to help us improve the CLI. We do not collect any source code as part of this.

You can opt out of sending usage data by setting the GRIT_TELEMETRY_DISABLED environment variable to true.