diff --git a/.changeset/auto-upgrade-off-json.md b/.changeset/auto-upgrade-off-json.md new file mode 100644 index 00000000000..3f95f540057 --- /dev/null +++ b/.changeset/auto-upgrade-off-json.md @@ -0,0 +1,5 @@ +--- +'@shopify/cli': minor +--- + +Add typed JSON output to `config autoupgrade off`. diff --git a/docs-shopify.dev/generated/generated_docs_data_v2.json b/docs-shopify.dev/generated/generated_docs_data_v2.json index 6c801684173..ba48244cff6 100644 --- a/docs-shopify.dev/generated/generated_docs_data_v2.json +++ b/docs-shopify.dev/generated/generated_docs_data_v2.json @@ -4361,9 +4361,45 @@ "description": "Print the command's JSON schemas.", "isOptional": true, "environmentValue": "SHOPIFY_FLAG_JSON_SCHEMA" + }, + { + "filePath": "docs-shopify.dev/commands/interfaces/config-autoupgrade-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-autoupgrade-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-autoupgrade-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-autoupgrade-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 configautoupgradeoff {\n /**\n * Print the command's JSON schemas.\n * @environment SHOPIFY_FLAG_JSON_SCHEMA\n */\n '--json-schema'?: ''\n}" + "value": "export interface configautoupgradeoff {\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}" } }, "configautoupgradeon": { diff --git a/packages/cli/README.md b/packages/cli/README.md index b35006dae81..b3624194936 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -3855,13 +3855,29 @@ Disable automatic upgrades for Shopify CLI. ``` USAGE - $ shopify config autoupgrade off [--json-schema] + $ shopify config autoupgrade 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 automatic upgrades for Shopify CLI. @@ -3870,6 +3886,28 @@ DESCRIPTION When auto-upgrade is disabled, Shopify CLI won't automatically update. Run `shopify upgrade` to update manually. To enable auto-upgrade, run `shopify config autoupgrade on`. + + + Use `--json-schema` to print the result, error, and event schemas. + + Output from `--json` conforms to the `AutoUpgradeResult` schema. + + ```json + { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + } + }, + "required": [ + "enabled" + ], + "additionalProperties": false, + "title": "AutoUpgradeResult", + "$schema": "http://json-schema.org/draft-07/schema#" + } + ``` ``` ## `shopify config autoupgrade on` diff --git a/packages/cli/oclif.manifest.json b/packages/cli/oclif.manifest.json index ec92bdf391d..8c67b23d42a 100644 --- a/packages/cli/oclif.manifest.json +++ b/packages/cli/oclif.manifest.json @@ -5804,16 +5804,48 @@ ], "args": { }, - "description": "Disable automatic upgrades for Shopify CLI.\n\n When auto-upgrade is disabled, Shopify CLI won't automatically update. Run `shopify upgrade` to update manually.\n\n To enable auto-upgrade, run `shopify config autoupgrade on`.\n", + "description": "Disable automatic upgrades for Shopify CLI.\n\n When auto-upgrade is disabled, Shopify CLI won't automatically update. Run `shopify upgrade` to update manually.\n\n To enable auto-upgrade, run `shopify config autoupgrade on`.\n\n\nUse `--json-schema` to print the result, error, and event schemas.\n\nOutput from `--json` conforms to the `AutoUpgradeResult` 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\": \"AutoUpgradeResult\",\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\n```", "descriptionWithMarkdown": "Disable automatic upgrades for Shopify CLI.\n\n When auto-upgrade is disabled, Shopify CLI won't automatically update. Run `shopify upgrade` to update manually.\n\n To enable auto-upgrade, run `shopify config autoupgrade on`.\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/cli/src/cli/commands/config/autoupgrade/autoupgrade.test.ts b/packages/cli/src/cli/commands/config/autoupgrade/autoupgrade.test.ts index 9b474bbe656..f8236097a54 100644 --- a/packages/cli/src/cli/commands/config/autoupgrade/autoupgrade.test.ts +++ b/packages/cli/src/cli/commands/config/autoupgrade/autoupgrade.test.ts @@ -1,4 +1,5 @@ import AutoupgradeOn from './on.js' +import AutoupgradeOff from './off.js' import AutoupgradeStatus from './status.js' import {autoUpgradeJsonOutputSchema} from '../../../services/commands/config/autoupgrade/types.js' import {getAutoUpgradeEnabled, setAutoUpgradeEnabled} from '@shopify/cli-kit/node/upgrade' @@ -25,6 +26,7 @@ afterEach(() => { const commands = [ {name: 'status', command: AutoupgradeStatus, enabled: false}, {name: 'on', command: AutoupgradeOn, enabled: true}, + {name: 'off', command: AutoupgradeOff, enabled: false}, ] test.each(commands)('$name exposes the result schema and JSON flags in help', ({command}) => { diff --git a/packages/cli/src/cli/commands/config/autoupgrade/constants.ts b/packages/cli/src/cli/commands/config/autoupgrade/constants.ts deleted file mode 100644 index aea28e71b97..00000000000 --- a/packages/cli/src/cli/commands/config/autoupgrade/constants.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const autoUpgradeStatus = { - on: 'Auto-upgrade on. Shopify CLI will update automatically after each command.', - off: "Auto-upgrade off. You'll need to run `shopify upgrade` to update manually.", -} as const diff --git a/packages/cli/src/cli/commands/config/autoupgrade/off.test.ts b/packages/cli/src/cli/commands/config/autoupgrade/off.test.ts index 4817cb3b9c2..15d802ff6e8 100644 --- a/packages/cli/src/cli/commands/config/autoupgrade/off.test.ts +++ b/packages/cli/src/cli/commands/config/autoupgrade/off.test.ts @@ -1,6 +1,5 @@ import AutoupgradeOff from './off.js' import {setAutoUpgradeEnabled} from '@shopify/cli-kit/node/upgrade' -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('@shopify/cli-kit/node/upgrade') describe('AutoupgradeOff', () => { test('disables auto-upgrade', async () => { // Given - const config = new Config({root: __dirname}) const outputMock = mockAndCaptureOutput() // When - await new AutoupgradeOff([], config).run() + await AutoupgradeOff.run([], import.meta.url) // Then expect(setAutoUpgradeEnabled).toBeCalledWith(false) diff --git a/packages/cli/src/cli/commands/config/autoupgrade/off.ts b/packages/cli/src/cli/commands/config/autoupgrade/off.ts index 267958ee570..92bdd1355dc 100644 --- a/packages/cli/src/cli/commands/config/autoupgrade/off.ts +++ b/packages/cli/src/cli/commands/config/autoupgrade/off.ts @@ -1,7 +1,8 @@ -import {autoUpgradeStatus} from './constants.js' -import {setAutoUpgradeEnabled} from '@shopify/cli-kit/node/upgrade' +import {configureAutoUpgrade} from '../../../services/commands/config/autoupgrade/index.js' +import {presentAutoUpgradeResult} from '../../../services/commands/config/autoupgrade/result.js' +import {autoUpgradeJsonOutputSchema} from '../../../services/commands/config/autoupgrade/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 AutoupgradeOff extends Command { static summary = 'Disable automatic upgrades for Shopify CLI.' @@ -15,8 +16,18 @@ export default class AutoupgradeOff extends Command { static description = this.descriptionForHelp() + static flags = { + ...globalFlags, + ...jsonFlag, + } + + static get jsonOutputSchema() { + return autoUpgradeJsonOutputSchema + } + async run(): Promise { - setAutoUpgradeEnabled(false) - renderInfo({body: autoUpgradeStatus.off}) + const {flags} = await this.parse(AutoupgradeOff) + const result = configureAutoUpgrade(false) + presentAutoUpgradeResult(result, flags.json ? 'json' : 'text') } } 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 5a54fb83c75..b300955e29d 100644 --- a/packages/eslint-plugin-cli/rules/json-output-command-exceptions.js +++ b/packages/eslint-plugin-cli/rules/json-output-command-exceptions.js @@ -34,7 +34,6 @@ const commandExceptions = [ 'packages/app/src/cli/commands/app/webhook/trigger.ts', 'packages/cli/src/cli/commands/auth/login.ts', 'packages/cli/src/cli/commands/auth/logout.ts', - 'packages/cli/src/cli/commands/config/autoupgrade/off.ts', 'packages/cli/src/cli/commands/doc/fetch.ts', 'packages/cli/src/cli/commands/doc/search.ts', 'packages/cli/src/cli/commands/upgrade.ts',