Skip to content

Commit d3928c5

Browse files
committed
fix: update match pattern docs. Add ReadMe associated pattern test.
1 parent 94d4b15 commit d3928c5

File tree

5 files changed

+182
-72
lines changed

5 files changed

+182
-72
lines changed

README.md

Lines changed: 121 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
DevCycle CLI & MCP Server
2-
=========================
1+
# DevCycle CLI & MCP Server
32

43
This repository contains the DevCycle CLI for managing feature flags from the command line, plus an MCP (Model Context Protocol) server that enables AI coding assistants to interact with DevCycle.
54

@@ -8,7 +7,7 @@ Major features include:
87
- Fully manage your Features, Variables, Variations and Targeting Rules from the command line
98
- Detect and list DevCycle Variable usages in your codebase
109
- Manage your Self-Targeting Overrides to quickly switch between Variable values
11-
- Generate type definitions for type-safe usage of DevCycle (Typescript only)
10+
- Generate type definitions for type-safe usage of DevCycle (TypeScript only)
1211
- MCP (Model Context Protocol) server for AI-powered feature flag management with Cursor and Claude
1312

1413
The CLI can be customized in several ways using command-line args or by creating a [configuration file](#repo-configuration).
@@ -18,14 +17,15 @@ The CLI can be customized in several ways using command-line args or by creating
1817
[![License](https://img.shields.io/npm/l/@devcycle/cli.svg)](https://github.com/DevCycleHQ/cli/blob/main/package.json)
1918

2019
<!-- toc -->
21-
* [Command Topics](#command-topics)
20+
21+
- [Command Topics](#command-topics)
2222
<!-- tocstop -->
2323

24-
## MCP Server for AI Assistants
24+
### MCP Server for AI Assistants
2525

2626
The DevCycle MCP (Model Context Protocol) server enables AI coding assistants like Cursor and Claude to manage feature flags directly from your development environment. DevCycle offers a hosted MCP server that requires no local installation.
2727

28-
### Quick Setup (No Installation Required)
28+
#### Quick Setup (No Installation Required)
2929

3030
1. **Configure your AI assistant to use the hosted MCP server:**
3131

@@ -48,10 +48,7 @@ The DevCycle MCP (Model Context Protocol) server enables AI coding assistants li
4848
"mcpServers": {
4949
"devcycle": {
5050
"command": "npx",
51-
"args": [
52-
"mcp-remote",
53-
"https://mcp.devcycle.com/mcp"
54-
]
51+
"args": ["mcp-remote", "https://mcp.devcycle.com/mcp"]
5552
}
5653
}
5754
}
@@ -63,11 +60,11 @@ Your AI assistant can now create, update, and manage feature flags on your behal
6360

6461
For local installation options, detailed configuration, available tools, and advanced usage, see the [complete MCP documentation](docs/mcp.md).
6562

66-
## CLI Documentation
63+
### CLI Documentation
6764

68-
## Setup
65+
### Setup
6966

70-
### Install the CLI
67+
#### Install the CLI
7168

7269
Using NPM
7370

@@ -82,13 +79,13 @@ $ brew tap devcyclehq/cli
8279
$ brew install devcycle
8380
```
8481

85-
## Authentication
82+
### Authentication
8683

8784
Many of the CLI commands require DevCycle API authorization. There are several ways to provide these credentials.
8885

89-
### Using Access Tokens (preferred)
86+
#### Using Access Tokens (preferred)
9087

91-
#### Login Command
88+
##### Login Command
9289

9390
By using the [`login sso` command](docs/login.md#dvc-login-sso), the CLI will retrieve and store an access token, which is valid for 24 hours.
9491

@@ -100,13 +97,13 @@ To switch organizations once logged in, the [`organizations select` command](doc
10097

10198
If executing the CLI in a containerized environment, please ensure one of the following PORTs can be accessed via Port Forwarding: 2194 (default), 2195, 2196 or 8080. This will allow the authentication process to complete and set the access token appropriately.
10299

103-
#### Repo Init Command
100+
##### Repo Init Command
104101

105102
The [`repo init` command](docs/repo.md#dvc-repo-init) behaves in the same way as `login sso`, but creates a [repo configuration file](#repo-configuration) and stores the project and organization choices there instead.
106103

107-
### Using Client Credentials
104+
#### Using Client Credentials
108105

109-
#### Client Credentials in Auth File
106+
##### Client Credentials in Auth File
110107

111108
Use the [`dvc status` command](docs/status.md#dvc-status) to find the configuration file location for your platform. The credentials can be stored in the file pointed to by the Auth config path. Create the file if it does not exist, with the following contents.
112109

@@ -122,15 +119,15 @@ The default location is based on the [oclif configDir](https://oclif.io/docs/con
122119
123120
If you intend to run the CLI using options that override config file locations, the [`dvc status` command](docs/status.md#dvc-status) command can be run with those options to confirm that the file locations are as expected.
124121

125-
### Project Selection
122+
#### Project Selection
126123

127124
You also need to specify the default project ID for the CLI to use.
128125

129126
If there is a repo configuration file, the [`dvc diff`](docs/diff.md) and [`dvc usages`](docs/usages.md) commands will use the project defined there.
130127

131128
Otherwise, this is chosen during login or set using the [project select command](docs/projects.md#dvc-projects-select)
132129

133-
### Environment Variables
130+
#### Environment Variables
134131

135132
Set the following environment variables:
136133

@@ -140,61 +137,65 @@ $ export DEVCYCLE_CLIENT_SECRET=<your client secret>
140137
$ export DEVCYCLE_PROJECT_KEY=<your project key>
141138
```
142139

143-
### Command-Line Arguments
140+
#### Command-Line Arguments
144141

145142
The CLI can be run with the following arguments:
146143

147144
```sh-session
148145
$ dvc --client-id=<your client id> --client-secret=<your client secret> --project=<your project key>
149146
```
150147

151-
### Github Action
148+
#### GitHub Action
152149

153-
The Devcycle Github actions are configured with auth information through the `project-key`, `client-id` and `client-secret` configuration parameters. This is passed to the CLI via command line arguments.
150+
The DevCycle GitHub actions are configured with auth information through the `project-key`, `client-id` and `client-secret` configuration parameters. This is passed to the CLI via command line arguments.
154151

155-
## Usage
152+
### Usage
156153

157154
<!-- usage -->
155+
158156
```sh-session
159157
$ npm install -g @devcycle/cli
160158
$ dvc COMMAND
161159
running command...
162160
$ dvc (--version)
163-
@devcycle/cli/6.1.4 linux-x64 node-v22.20.0
161+
@devcycle/cli/6.1.2 linux-x64 node-v22.20.0
164162
$ dvc --help [COMMAND]
165163
USAGE
166164
$ dvc COMMAND
167165
...
168166
```
167+
169168
<!-- usagestop -->
170169

171170
<!-- commands -->
172-
# Command Topics
173-
174-
* [`dvc alias`](docs/alias.md) - Manage repository variable aliases.
175-
* [`dvc autocomplete`](docs/autocomplete.md) - display autocomplete installation instructions
176-
* [`dvc cleanup`](docs/cleanup.md) - Replace a DevCycle variable with a static value in the current version of your code. Currently only JavaScript is supported.
177-
* [`dvc diff`](docs/diff.md) - Print a diff of DevCycle variable usage between two versions of your code.
178-
* [`dvc environments`](docs/environments.md) - Create a new Environment for an existing Feature.
179-
* [`dvc features`](docs/features.md) - Create, view, or modify Features with the Management API.
180-
* [`dvc generate`](docs/generate.md) - Generate Devcycle related files.
181-
* [`dvc help`](docs/help.md) - Display help for dvc.
182-
* [`dvc identity`](docs/identity.md) - View or manage your DevCycle Identity.
183-
* [`dvc keys`](docs/keys.md) - Retrieve SDK keys from the Management API.
184-
* [`dvc login`](docs/login.md) - Log in to DevCycle.
185-
* [`dvc logout`](docs/logout.md) - Discards any auth configuration that has been stored in the auth configuration file.
186-
* [`dvc organizations`](docs/organizations.md) - List or switch organizations.
187-
* [`dvc overrides`](docs/overrides.md) - Create, view, or modify Overrides for a Project with the Management API.
188-
* [`dvc projects`](docs/projects.md) - Create, or view Projects with the Management API.
189-
* [`dvc repo`](docs/repo.md) - Manage repository configuration.
190-
* [`dvc status`](docs/status.md) - Check CLI status.
191-
* [`dvc targeting`](docs/targeting.md) - Create, view, or modify Targeting Rules for a Feature with the Management API.
192-
* [`dvc usages`](docs/usages.md) - Print all DevCycle variable usages in the current version of your code.
193-
* [`dvc variables`](docs/variables.md) - Create, view, or modify Variables with the Management API.
194-
* [`dvc variations`](docs/variations.md) - Create a new Variation for an existing Feature.
171+
172+
## Command Topics
173+
174+
- [`dvc alias`](docs/alias.md) - Manage repository variable aliases.
175+
- [`dvc autocomplete`](docs/autocomplete.md) - display autocomplete installation instructions
176+
- [`dvc cleanup`](docs/cleanup.md) - Replace a DevCycle variable with a static value in the current version of your code. Currently only JavaScript is supported.
177+
- [`dvc diff`](docs/diff.md) - Print a diff of DevCycle variable usage between two versions of your code.
178+
- [`dvc environments`](docs/environments.md) - Create a new Environment for an existing Feature.
179+
- [`dvc features`](docs/features.md) - Create, view, or modify Features with the Management API.
180+
- [`dvc generate`](docs/generate.md) - Generate DevCycle related files.
181+
- [`dvc help`](docs/help.md) - Display help for dvc.
182+
- [`dvc identity`](docs/identity.md) - View or manage your DevCycle Identity.
183+
- [`dvc keys`](docs/keys.md) - Retrieve SDK keys from the Management API.
184+
- [`dvc login`](docs/login.md) - Log in to DevCycle.
185+
- [`dvc logout`](docs/logout.md) - Discards any auth configuration that has been stored in the auth configuration file.
186+
- [`dvc organizations`](docs/organizations.md) - List or switch organizations.
187+
- [`dvc overrides`](docs/overrides.md) - Create, view, or modify Overrides for a Project with the Management API.
188+
- [`dvc projects`](docs/projects.md) - Create, or view Projects with the Management API.
189+
- [`dvc repo`](docs/repo.md) - Manage repository configuration.
190+
- [`dvc status`](docs/status.md) - Check CLI status.
191+
- [`dvc targeting`](docs/targeting.md) - Create, view, or modify Targeting Rules for a Feature with the Management API.
192+
- [`dvc usages`](docs/usages.md) - Print all DevCycle variable usages in the current version of your code.
193+
- [`dvc variables`](docs/variables.md) - Create, view, or modify Variables with the Management API.
194+
- [`dvc variations`](docs/variations.md) - Create a new Variation for an existing Feature.
195195

196196
<!-- commandsstop -->
197-
## Repo Configuration
197+
198+
### Repo Configuration
198199

199200
The following commands can only be run from the root of a configured repository
200201

@@ -208,43 +209,48 @@ location for this file is `<REPO ROOT>/.devcycle/config.yml`.
208209

209210
This location can be overridden using the `--repo-config-path` flag.
210211

212+
Create or update this file using the [`dvc repo init`](docs/repo.md#dvc-repo-init) command.
213+
211214
The configuration file format is documented below:
212215

213216
```yml
214-
## the project and organization to use when connecting to the DevCycle Rest API for this repo
215-
project: "project-key"
217+
### the project and organization to use when connecting to the DevCycle Rest API for this repo
218+
project: 'project-key'
216219
org:
217-
id: "org_xxxxxx"
218-
name: "unique-org-key"
219-
display_name: "Human Readable Org Name"
220-
## block for configuring "code insights" features like diff and variable usage scanning
221-
## use this section to improve the detection of DevCycle usage within your code
220+
id: 'org_xxxxxx'
221+
name: 'unique-org-key'
222+
display_name: 'Human Readable Org Name'
223+
### block for configuring "code insights" features like diff and variable usage scanning
224+
### use this section to improve the detection of DevCycle usage within your code
222225
codeInsights:
223-
## add additional names to check for when looking for instances of DVCClient from an SDK
226+
### add additional names to check for when looking for instances of DVCClient from an SDK
224227
clientNames:
225-
- "dvcClient"
226-
## map the values used in your code to the corresponding variable key in DevCycle
228+
- 'dvcClient'
229+
### map the values used in your code to the corresponding variable key in DevCycle
227230
variableAliases:
228-
"VARIABLES.ENABLE_V1": "enable-v1"
229-
## additional regex patterns used to match variables for a specific file extension
231+
'VARIABLES.ENABLE_V1': 'enable-v1'
232+
### additional regex patterns used to match variables for a specific file extension
230233
matchPatterns:
231-
## file extension to override for, containing a list of patterns to use
234+
### file extension to override for, containing a list of patterns to use
232235
js:
233236
- dvcClient\.variable\(\s*["']([^"']*)["']
234-
## an array of file glob patterns to include in usage scan
237+
### an array of file glob patterns to include in usage scan
235238
includeFiles:
236-
- "*.[jt]s"
237-
## an array of file glob patterns to exclude from usage scan
239+
- '*.[jt]s'
240+
### an array of file glob patterns to exclude from usage scan
238241
excludeFiles:
239-
- "dist/*"
242+
- 'dist/*'
240243
```
241244

242-
### Match Patterns
245+
### Match Patterns and Aliases
243246

244247
When identifying variable usages in the code, the CLI will identify DevCycle SDK methods by default. To capture
245-
other usages you may define match patterns. Match patterns are defined by file extension, and each pattern should
246-
contain exactly one capture group which matches the key of the variable. Make sure the captured value contains the
247-
entire key parameter (including quotes, if applicable).
248+
other usages you may define match patterns. Match patterns are defined by file extension.
249+
250+
:::note
251+
Each pattern must include exactly one capture group for the variable key. Capture the entire key value
252+
(including surrounding quotes if you choose the “with quotes” pattern).
253+
:::
248254

249255
Match patterns can be defined in the configuration file, for example:
250256

@@ -263,14 +269,57 @@ codeInsights:
263269
- customVariableGetter\(\s*["']([^"']*)["']
264270
```
265271

272+
#### Capturing with or without quotes
273+
274+
Match patterns can capture variable keys with or without quotes, which affects whether aliases are needed:
275+
276+
With quotes:
277+
278+
```yml
279+
# Pattern captures the key including surrounding quotes
280+
- dvcClient\.variable\(\s*(["'][^"']*["'])\s*,
281+
```
282+
283+
- Matches: `dvcClient.variable('my-variable', default)`
284+
- Captures: `'my-variable'` (with quotes)
285+
286+
Without quotes (aliases or generated constants required):
287+
288+
```yml
289+
# Pattern strips quotes, capturing only the content
290+
- dvcClient\.variable\(\s*["']([^"']*)["']
291+
```
292+
293+
- Matches: `dvcClient.variable('my-variable', default)`
294+
- Captures: `my-variable`
295+
266296
Match patterns can also be passed directly to relevant commands using the `--match-pattern` flag:
267297

268298
```bash
269-
dvc usages --match-pattern ts="customVariableGetter\(\s*[\"']([^\"']*)[\"']" js="customVariableGetter\(\s*[\"']([^\"']*)[\"']"
299+
dvc usages --match-pattern ts="customVariableGetter\(\s*["']([^"']*)["']" js="customVariableGetter\(\s*["']([^"']*)["']"
270300
```
271301

272302
When testing your regex the `--show-regex` flag can be helpful. This will print all patterns used to find matches in your codebase.
273303

274304
```bash
275305
dvc usages --show-regex
276306
```
307+
308+
#### Custom Wrapper Functions
309+
310+
If you use wrapper functions around the SDK, add patterns for them.
311+
312+
**Example: Custom wrapper functions**
313+
314+
```yml
315+
codeInsights:
316+
matchPatterns:
317+
ts:
318+
# Matches: getFeatureFlag('my-variable', defaultValue)
319+
- getFeatureFlag\(\s*([^,)]*)\s*,
320+
# Matches: isFeatureEnabled('my-variable')
321+
- isFeatureEnabled\(\s*([^,)]*)\s*\)
322+
tsx:
323+
# Matches: useFeatureFlag('my-variable', defaultValue)
324+
- useFeatureFlag\(\s*([^,)]*)\s*,
325+
```

src/commands/diff/__snapshots__/diff.test.ts.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`diff > correctly matches using custom patterns from README examples 1`] = `
4+
"
5+
DevCycle Variable Changes:
6+
7+
🟢 2 Variables Added
8+
🔴 1 Variable Removed
9+
10+
🟢 Added
11+
12+
1. my-variable
13+
Location: test-utils/fixtures/diff/sampleDiff.ts:L1
14+
2. enable-feature
15+
Location: test-utils/fixtures/diff/sampleDiff.ts:L2
16+
17+
🔴 Removed
18+
19+
1. removed-variable
20+
Location: test-utils/fixtures/diff/sampleDiff.ts:L1
21+
"
22+
`;
23+
324
exports[`diff > enriches output with API data 1`] = `
425
"
526
DevCycle Variable Changes:

src/commands/diff/diff.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,22 @@ describe('diff', () => {
292292
.it('identifies aliased variables specified in config file', (ctx) => {
293293
expect(ctx.stdout).toMatchSnapshot()
294294
})
295+
296+
test.stdout()
297+
.command([
298+
'diff',
299+
'--file',
300+
'test-utils/fixtures/diff/readme-examples',
301+
'--no-api',
302+
'--repo-config-path',
303+
'./test-utils/fixtures/configs/readmeExamplesConfig.yml',
304+
])
305+
.it(
306+
'correctly matches using custom patterns from README examples',
307+
(ctx) => {
308+
expect(ctx.stdout).toMatchSnapshot()
309+
},
310+
)
295311
test.stdout()
296312
.command([
297313
'diff',

0 commit comments

Comments
 (0)