diff --git a/.changeset/autocorrect-off-json.md b/.changeset/autocorrect-off-json.md new file mode 100644 index 00000000000..8c8fd453c20 --- /dev/null +++ b/.changeset/autocorrect-off-json.md @@ -0,0 +1,5 @@ +--- +'@shopify/cli': minor +--- + +Add typed JSON output to `config autocorrect` commands diff --git a/docs-shopify.dev/generated/generated_docs_data_v2.json b/docs-shopify.dev/generated/generated_docs_data_v2.json index c01c8fea28f..bd1fca43978 100644 --- a/docs-shopify.dev/generated/generated_docs_data_v2.json +++ b/docs-shopify.dev/generated/generated_docs_data_v2.json @@ -5109,9 +5109,45 @@ "description": "Print the command's JSON schemas.", "isOptional": true, "environmentValue": "SHOPIFY_FLAG_JSON_SCHEMA" + }, + { + "filePath": "docs-shopify.dev/commands/interfaces/config-autocorrect-off.interface.ts", + "syntaxKind": "PropertySignature", + "name": "--no-color", + "value": "''", + "description": "Disable color output.", + "isOptional": true, + "environmentValue": "SHOPIFY_FLAG_NO_COLOR" + }, + { + "filePath": "docs-shopify.dev/commands/interfaces/config-autocorrect-off.interface.ts", + "syntaxKind": "PropertySignature", + "name": "--no-input", + "value": "''", + "description": "Disable interactive prompts and browser authentication.", + "isOptional": true, + "environmentValue": "SHOPIFY_FLAG_NO_INPUT" + }, + { + "filePath": "docs-shopify.dev/commands/interfaces/config-autocorrect-off.interface.ts", + "syntaxKind": "PropertySignature", + "name": "--verbose", + "value": "''", + "description": "Increase the verbosity of the output. May include sensitive data.", + "isOptional": true, + "environmentValue": "SHOPIFY_FLAG_VERBOSE" + }, + { + "filePath": "docs-shopify.dev/commands/interfaces/config-autocorrect-off.interface.ts", + "syntaxKind": "PropertySignature", + "name": "-j, --json", + "value": "''", + "description": "Output the result as JSON. Automatically disables color output.", + "isOptional": true, + "environmentValue": "SHOPIFY_FLAG_JSON" } ], - "value": "export interface configautocorrectoff {\n /**\n * Print the command's JSON schemas.\n * @environment SHOPIFY_FLAG_JSON_SCHEMA\n */\n '--json-schema'?: ''\n}" + "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}" } }, "configautocorrecton": { diff --git a/packages/cli/README.md b/packages/cli/README.md index 3011d958bd7..bcfcc119a67 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -8062,13 +8062,29 @@ Disable autocorrect. Off by default. ``` USAGE - $ shopify config autocorrect off [--json-schema] + $ shopify config autocorrect off [-j] [--json-schema] [--no-color] [--no-input] [--verbose] FLAGS + -j, --json + Output the result as JSON. Automatically disables color output. + [env: SHOPIFY_FLAG_JSON] + --json-schema Print the command's JSON schemas. [env: SHOPIFY_FLAG_JSON_SCHEMA] + --no-color + Disable color output. + [env: SHOPIFY_FLAG_NO_COLOR] + + --no-input + Disable interactive prompts and browser authentication. + [env: SHOPIFY_FLAG_NO_INPUT] + + --verbose + Increase the verbosity of the output. May include sensitive data. + [env: SHOPIFY_FLAG_VERBOSE] + DESCRIPTION Disable autocorrect. Off by default. @@ -8078,6 +8094,28 @@ DESCRIPTION available. When autocorrection is disabled, you need to confirm that you want to run corrections for mistyped commands. + + + Use `--json-schema` to print the result, error, and event schemas. + + Output from `--json` conforms to the `AutocorrectResult` schema. + + ```json + { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + } + }, + "required": [ + "enabled" + ], + "additionalProperties": false, + "title": "AutocorrectResult", + "$schema": "http://json-schema.org/draft-07/schema#" + } + ``` ``` ## `shopify config autocorrect on` diff --git a/packages/cli/oclif.manifest.json b/packages/cli/oclif.manifest.json index 0846ad618aa..9c54e3ce5eb 100644 --- a/packages/cli/oclif.manifest.json +++ b/packages/cli/oclif.manifest.json @@ -6004,16 +6004,48 @@ "args": { }, "customPluginName": "@shopify/plugin-did-you-mean", - "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", + "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```", "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", "enableJsonFlag": false, "flags": { + "json": { + "allowNo": false, + "char": "j", + "description": "Output the result as JSON. Automatically disables color output.", + "env": "SHOPIFY_FLAG_JSON", + "hidden": false, + "name": "json", + "type": "boolean" + }, "json-schema": { "allowNo": false, "description": "Print the command's JSON schemas.", "env": "SHOPIFY_FLAG_JSON_SCHEMA", "name": "json-schema", "type": "boolean" + }, + "no-color": { + "allowNo": false, + "description": "Disable color output.", + "env": "SHOPIFY_FLAG_NO_COLOR", + "hidden": false, + "name": "no-color", + "type": "boolean" + }, + "no-input": { + "allowNo": false, + "description": "Disable interactive prompts and browser authentication.", + "env": "SHOPIFY_FLAG_NO_INPUT", + "name": "no-input", + "type": "boolean" + }, + "verbose": { + "allowNo": false, + "description": "Increase the verbosity of the output. May include sensitive data.", + "env": "SHOPIFY_FLAG_VERBOSE", + "hidden": false, + "name": "verbose", + "type": "boolean" } }, "hasDynamicHelp": false, diff --git a/packages/eslint-plugin-cli/rules/json-output-command-exceptions.js b/packages/eslint-plugin-cli/rules/json-output-command-exceptions.js index e6c51adc2b0..a2165527d7a 100644 --- a/packages/eslint-plugin-cli/rules/json-output-command-exceptions.js +++ b/packages/eslint-plugin-cli/rules/json-output-command-exceptions.js @@ -2,7 +2,6 @@ const commandExceptions = [ // Existing finite commands awaiting migration. Remove entries as they adopt typed JSON output. // Do not add new finite commands to this section. - 'packages/plugin-did-you-mean/src/commands/config/autocorrect/off.ts', // App Security commands, launched before adopting typed JSON output. Remove entries as they adopt it. 'packages/app/src/cli/commands/app/security/check.ts', diff --git a/packages/plugin-did-you-mean/src/commands/config/autocorrect/autocorrect.test.ts b/packages/plugin-did-you-mean/src/commands/config/autocorrect/autocorrect.test.ts index 76ea0aed797..ebaecd6775d 100644 --- a/packages/plugin-did-you-mean/src/commands/config/autocorrect/autocorrect.test.ts +++ b/packages/plugin-did-you-mean/src/commands/config/autocorrect/autocorrect.test.ts @@ -1,5 +1,6 @@ import AutocorrectStatus from './status.js' import AutocorrectOn from './on.js' +import AutocorrectOff from './off.js' import {isAutocorrectEnabled, setAutocorrect} from '../../../services/conf.js' import {autocorrectJsonOutputSchema} from '../../../services/autocorrect/types.js' import {launchCLI} from '@shopify/cli-kit/node/cli-launcher' @@ -23,6 +24,7 @@ afterEach(() => { const commands = [ {name: 'status', command: AutocorrectStatus, enabled: false}, {name: 'on', command: AutocorrectOn, enabled: true}, + {name: 'off', command: AutocorrectOff, enabled: false}, ] test.each(commands)('$name exposes the result schema and JSON flags in help', ({command}) => { diff --git a/packages/plugin-did-you-mean/src/commands/config/autocorrect/off.test.ts b/packages/plugin-did-you-mean/src/commands/config/autocorrect/off.test.ts index f55cd877fe8..a32429bf0c8 100644 --- a/packages/plugin-did-you-mean/src/commands/config/autocorrect/off.test.ts +++ b/packages/plugin-did-you-mean/src/commands/config/autocorrect/off.test.ts @@ -1,6 +1,5 @@ import AutocorrectOff from './off.js' import {setAutocorrect} from '../../../services/conf.js' -import {Config} from '@oclif/core' import {describe, expect, vi, test} from 'vitest' import {mockAndCaptureOutput} from '@shopify/cli-kit/node/testing/output' @@ -9,11 +8,10 @@ vi.mock('../../../services/conf.js') describe('AutocorrectOff', () => { test('Update autocorrect config to disabled', async () => { // Given - const config = new Config({root: __dirname}) const outputMock = mockAndCaptureOutput() // When - await new AutocorrectOff([], config).run() + await AutocorrectOff.run([], import.meta.url) // Then expect(setAutocorrect).toBeCalledWith(false) diff --git a/packages/plugin-did-you-mean/src/commands/config/autocorrect/off.ts b/packages/plugin-did-you-mean/src/commands/config/autocorrect/off.ts index b56dbb1fd24..a06289c2e14 100644 --- a/packages/plugin-did-you-mean/src/commands/config/autocorrect/off.ts +++ b/packages/plugin-did-you-mean/src/commands/config/autocorrect/off.ts @@ -1,7 +1,8 @@ -import {autocorrectStatus} from '../../../services/constants.js' -import {setAutocorrect} from '../../../services/conf.js' +import {configureAutocorrect} from '../../../services/autocorrect/index.js' +import {presentAutocorrectResult} from '../../../services/autocorrect/result.js' +import {autocorrectJsonOutputSchema} from '../../../services/autocorrect/types.js' import Command from '@shopify/cli-kit/node/base-command' -import {renderInfo} from '@shopify/cli-kit/node/ui' +import {globalFlags, jsonFlag} from '@shopify/cli-kit/node/cli' export default class AutocorrectOff extends Command { static summary = 'Disable autocorrect. Off by default.' @@ -15,8 +16,18 @@ export default class AutocorrectOff extends Command { static description = this.descriptionForHelp() + static flags = { + ...globalFlags, + ...jsonFlag, + } + + static get jsonOutputSchema() { + return autocorrectJsonOutputSchema + } + async run(): Promise { - setAutocorrect(false) - renderInfo({body: autocorrectStatus.off}) + const {flags} = await this.parse(AutocorrectOff) + const result = configureAutocorrect(false) + presentAutocorrectResult(result, flags.json ? 'json' : 'text') } }