Skip to content

varar rename

varar rename changes a step expression and rewrites every sentence that matches it, so each one still matches afterwards. It runs the same engine as rename in the editor, without an editor, so a script or a coding agent can use it too.

Terminal window
varar rename 'I fly from {airport} to {airport}' 'I travel from {airport} to {airport}'
varar rename --dry-run '<old>' '<new>' # show the edits, write nothing
varar rename --json '<old>' '<new>' # machine-readable
src/varar/airport.steps.ts:9:11 I fly from {airport} to {airport} → I travel from {airport} to {airport}
varar/airport.md:7:1 I fly from LHR to JFK → I travel from LHR to JFK
2 edit(s) in 2 file(s)

The first argument is the expression exactly as the step definition writes it. The second is the new expression. Each sentence keeps its own values: LHR and JFK stay where they were.

A sentence matches a step only while its words match the expression. Change the expression by hand, miss one sentence, and that sentence becomes prose. It doesn’t fail: it stops being checked, and the example it belonged to may split in two. varar rename rewrites every sentence so it still matches, or changes nothing.

It changes no files and exits with code 1, giving the reason, when:

The rename… Why
uses an expression no step definition has Nothing to rename.
uses an expression two step definitions share It can’t tell which one you mean. Rename it in an editor, where you point at one.
adds a parameter, or changes a parameter’s type Every sentence would need a value only you can give. VS Code prompts for each one.
would also match sentences of explanation Those sentences would start running as examples. The error lists them: reword them, or pick different words.
can’t rewrite a sentence so that it still matches An optional or alternation group it can’t spell the way that sentence does.

A rename that removes a parameter goes ahead, and drops that value from every sentence.

Each edit prints as path:line:col old → new, with 1-based line and column. Paths are relative to the current directory.

With --json, the output is one object:

{
"ok": true,
"dryRun": false,
"edits": [
{ "path": "varar/airport.md", "line": 7, "col": 1, "oldText": "I fly from LHR to JFK", "newText": "I travel from LHR to JFK" }
],
"written": ["src/varar/airport.steps.ts", "varar/airport.md"]
}

A refusal is { "ok": false, "error": "…" }.

Code Meaning
0 Renamed, or with --dry-run, the rename would succeed.
1 Refused. No file changed.
2 Missing arguments.