Skip to content

Commit 7bd745d

Browse files
Add typed JSON output to autocorrect off
1 parent 6324dd7 commit 7bd745d

8 files changed

Lines changed: 133 additions & 12 deletions

File tree

‎.changeset/autocorrect-off-json.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/cli': minor
3+
---
4+
5+
Add typed JSON output to `config autocorrect off`.

‎docs-shopify.dev/generated/generated_docs_data_v2.json‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5109,9 +5109,45 @@
51095109
"description": "Print the command's JSON schemas.",
51105110
"isOptional": true,
51115111
"environmentValue": "SHOPIFY_FLAG_JSON_SCHEMA"
5112+
},
5113+
{
5114+
"filePath": "docs-shopify.dev/commands/interfaces/config-autocorrect-off.interface.ts",
5115+
"syntaxKind": "PropertySignature",
5116+
"name": "--no-color",
5117+
"value": "''",
5118+
"description": "Disable color output.",
5119+
"isOptional": true,
5120+
"environmentValue": "SHOPIFY_FLAG_NO_COLOR"
5121+
},
5122+
{
5123+
"filePath": "docs-shopify.dev/commands/interfaces/config-autocorrect-off.interface.ts",
5124+
"syntaxKind": "PropertySignature",
5125+
"name": "--no-input",
5126+
"value": "''",
5127+
"description": "Disable interactive prompts and browser authentication.",
5128+
"isOptional": true,
5129+
"environmentValue": "SHOPIFY_FLAG_NO_INPUT"
5130+
},
5131+
{
5132+
"filePath": "docs-shopify.dev/commands/interfaces/config-autocorrect-off.interface.ts",
5133+
"syntaxKind": "PropertySignature",
5134+
"name": "--verbose",
5135+
"value": "''",
5136+
"description": "Increase the verbosity of the output. May include sensitive data.",
5137+
"isOptional": true,
5138+
"environmentValue": "SHOPIFY_FLAG_VERBOSE"
5139+
},
5140+
{
5141+
"filePath": "docs-shopify.dev/commands/interfaces/config-autocorrect-off.interface.ts",
5142+
"syntaxKind": "PropertySignature",
5143+
"name": "-j, --json",
5144+
"value": "''",
5145+
"description": "Output the result as JSON. Automatically disables color output.",
5146+
"isOptional": true,
5147+
"environmentValue": "SHOPIFY_FLAG_JSON"
51125148
}
51135149
],
5114-
"value": "export interface configautocorrectoff {\n /**\n * Print the command's JSON schemas.\n * @environment SHOPIFY_FLAG_JSON_SCHEMA\n */\n '--json-schema'?: ''\n}"
5150+
"value": "export interface configautocorrectoff {\n /**\n * Output the result as JSON. Automatically disables color output.\n * @environment SHOPIFY_FLAG_JSON\n */\n '-j, --json'?: ''\n\n /**\n * Print the command's JSON schemas.\n * @environment SHOPIFY_FLAG_JSON_SCHEMA\n */\n '--json-schema'?: ''\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * Disable interactive prompts and browser authentication.\n * @environment SHOPIFY_FLAG_NO_INPUT\n */\n '--no-input'?: ''\n\n /**\n * Increase the verbosity of the output. May include sensitive data.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
51155151
}
51165152
},
51175153
"configautocorrecton": {

‎packages/cli/README.md‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8062,13 +8062,29 @@ Disable autocorrect. Off by default.
80628062
80638063
```
80648064
USAGE
8065-
$ shopify config autocorrect off [--json-schema]
8065+
$ shopify config autocorrect off [-j] [--json-schema] [--no-color] [--no-input] [--verbose]
80668066

80678067
FLAGS
8068+
-j, --json
8069+
Output the result as JSON. Automatically disables color output.
8070+
[env: SHOPIFY_FLAG_JSON]
8071+
80688072
--json-schema
80698073
Print the command's JSON schemas.
80708074
[env: SHOPIFY_FLAG_JSON_SCHEMA]
80718075

8076+
--no-color
8077+
Disable color output.
8078+
[env: SHOPIFY_FLAG_NO_COLOR]
8079+
8080+
--no-input
8081+
Disable interactive prompts and browser authentication.
8082+
[env: SHOPIFY_FLAG_NO_INPUT]
8083+
8084+
--verbose
8085+
Increase the verbosity of the output. May include sensitive data.
8086+
[env: SHOPIFY_FLAG_VERBOSE]
8087+
80728088
DESCRIPTION
80738089
Disable autocorrect. Off by default.
80748090

@@ -8078,6 +8094,28 @@ DESCRIPTION
80788094
available.
80798095

80808096
When autocorrection is disabled, you need to confirm that you want to run corrections for mistyped commands.
8097+
8098+
8099+
Use `--json-schema` to print the result, error, and event schemas.
8100+
8101+
Output from `--json` conforms to the `AutocorrectResult` schema.
8102+
8103+
```json
8104+
{
8105+
"type": "object",
8106+
"properties": {
8107+
"enabled": {
8108+
"type": "boolean"
8109+
}
8110+
},
8111+
"required": [
8112+
"enabled"
8113+
],
8114+
"additionalProperties": false,
8115+
"title": "AutocorrectResult",
8116+
"$schema": "http://json-schema.org/draft-07/schema#"
8117+
}
8118+
```
80818119
```
80828120
80838121
## `shopify config autocorrect on`

‎packages/cli/oclif.manifest.json‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6004,16 +6004,48 @@
60046004
"args": {
60056005
},
60066006
"customPluginName": "@shopify/plugin-did-you-mean",
6007-
"description": "Disable autocorrect. Off by default.\n\n When autocorrection is enabled, Shopify CLI automatically runs a corrected version of your command if a correction is available.\n\n When autocorrection is disabled, you need to confirm that you want to run corrections for mistyped commands.\n",
6007+
"description": "Disable autocorrect. Off by default.\n\n When autocorrection is enabled, Shopify CLI automatically runs a corrected version of your command if a correction is available.\n\n When autocorrection is disabled, you need to confirm that you want to run corrections for mistyped commands.\n\n\nUse `--json-schema` to print the result, error, and event schemas.\n\nOutput from `--json` conforms to the `AutocorrectResult` schema.\n\n```json\n{\n \"type\": \"object\",\n \"properties\": {\n \"enabled\": {\n \"type\": \"boolean\"\n }\n },\n \"required\": [\n \"enabled\"\n ],\n \"additionalProperties\": false,\n \"title\": \"AutocorrectResult\",\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\n```",
60086008
"descriptionWithMarkdown": "Disable autocorrect. Off by default.\n\n When autocorrection is enabled, Shopify CLI automatically runs a corrected version of your command if a correction is available.\n\n When autocorrection is disabled, you need to confirm that you want to run corrections for mistyped commands.\n",
60096009
"enableJsonFlag": false,
60106010
"flags": {
6011+
"json": {
6012+
"allowNo": false,
6013+
"char": "j",
6014+
"description": "Output the result as JSON. Automatically disables color output.",
6015+
"env": "SHOPIFY_FLAG_JSON",
6016+
"hidden": false,
6017+
"name": "json",
6018+
"type": "boolean"
6019+
},
60116020
"json-schema": {
60126021
"allowNo": false,
60136022
"description": "Print the command's JSON schemas.",
60146023
"env": "SHOPIFY_FLAG_JSON_SCHEMA",
60156024
"name": "json-schema",
60166025
"type": "boolean"
6026+
},
6027+
"no-color": {
6028+
"allowNo": false,
6029+
"description": "Disable color output.",
6030+
"env": "SHOPIFY_FLAG_NO_COLOR",
6031+
"hidden": false,
6032+
"name": "no-color",
6033+
"type": "boolean"
6034+
},
6035+
"no-input": {
6036+
"allowNo": false,
6037+
"description": "Disable interactive prompts and browser authentication.",
6038+
"env": "SHOPIFY_FLAG_NO_INPUT",
6039+
"name": "no-input",
6040+
"type": "boolean"
6041+
},
6042+
"verbose": {
6043+
"allowNo": false,
6044+
"description": "Increase the verbosity of the output. May include sensitive data.",
6045+
"env": "SHOPIFY_FLAG_VERBOSE",
6046+
"hidden": false,
6047+
"name": "verbose",
6048+
"type": "boolean"
60176049
}
60186050
},
60196051
"hasDynamicHelp": false,

‎packages/eslint-plugin-cli/rules/json-output-command-exceptions.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
const commandExceptions = [
33
// Existing finite commands awaiting migration. Remove entries as they adopt typed JSON output.
44
// Do not add new finite commands to this section.
5-
'packages/plugin-did-you-mean/src/commands/config/autocorrect/off.ts',
65
'packages/theme/src/cli/commands/theme/check.ts',
76
'packages/theme/src/cli/commands/theme/init.ts',
87
'packages/theme/src/cli/commands/theme/metafields/pull.ts',

‎packages/plugin-did-you-mean/src/commands/config/autocorrect/autocorrect.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import AutocorrectStatus from './status.js'
22
import AutocorrectOn from './on.js'
3+
import AutocorrectOff from './off.js'
34
import {isAutocorrectEnabled, setAutocorrect} from '../../../services/conf.js'
45
import {autocorrectJsonOutputSchema} from '../../../services/autocorrect/types.js'
56
import {launchCLI} from '@shopify/cli-kit/node/cli-launcher'
@@ -23,6 +24,7 @@ afterEach(() => {
2324
const commands = [
2425
{name: 'status', command: AutocorrectStatus, enabled: false},
2526
{name: 'on', command: AutocorrectOn, enabled: true},
27+
{name: 'off', command: AutocorrectOff, enabled: false},
2628
]
2729

2830
test.each(commands)('$name exposes the result schema and JSON flags in help', ({command}) => {

‎packages/plugin-did-you-mean/src/commands/config/autocorrect/off.test.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import AutocorrectOff from './off.js'
22
import {setAutocorrect} from '../../../services/conf.js'
3-
import {Config} from '@oclif/core'
43
import {describe, expect, vi, test} from 'vitest'
54
import {mockAndCaptureOutput} from '@shopify/cli-kit/node/testing/output'
65

@@ -9,11 +8,10 @@ vi.mock('../../../services/conf.js')
98
describe('AutocorrectOff', () => {
109
test('Update autocorrect config to disabled', async () => {
1110
// Given
12-
const config = new Config({root: __dirname})
1311
const outputMock = mockAndCaptureOutput()
1412

1513
// When
16-
await new AutocorrectOff([], config).run()
14+
await AutocorrectOff.run([], import.meta.url)
1715

1816
// Then
1917
expect(setAutocorrect).toBeCalledWith(false)

‎packages/plugin-did-you-mean/src/commands/config/autocorrect/off.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import {autocorrectStatus} from '../../../services/constants.js'
2-
import {setAutocorrect} from '../../../services/conf.js'
1+
import {configureAutocorrect} from '../../../services/autocorrect/index.js'
2+
import {presentAutocorrectResult} from '../../../services/autocorrect/result.js'
3+
import {autocorrectJsonOutputSchema} from '../../../services/autocorrect/types.js'
34
import Command from '@shopify/cli-kit/node/base-command'
4-
import {renderInfo} from '@shopify/cli-kit/node/ui'
5+
import {globalFlags, jsonFlag} from '@shopify/cli-kit/node/cli'
56

67
export default class AutocorrectOff extends Command {
78
static summary = 'Disable autocorrect. Off by default.'
@@ -15,8 +16,18 @@ export default class AutocorrectOff extends Command {
1516

1617
static description = this.descriptionForHelp()
1718

19+
static flags = {
20+
...globalFlags,
21+
...jsonFlag,
22+
}
23+
24+
static get jsonOutputSchema() {
25+
return autocorrectJsonOutputSchema
26+
}
27+
1828
async run(): Promise<void> {
19-
setAutocorrect(false)
20-
renderInfo({body: autocorrectStatus.off})
29+
const {flags} = await this.parse(AutocorrectOff)
30+
const result = configureAutocorrect(false)
31+
presentAutocorrectResult(result, flags.json ? 'json' : 'text')
2132
}
2233
}

0 commit comments

Comments
 (0)