Skip to content

Commit 83a7548

Browse files
committed
--json -j should not use color
1 parent 0b41bff commit 83a7548

4 files changed

Lines changed: 42 additions & 25 deletions

File tree

packages/cli-kit/src/public/node/cli.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ describe('cli', () => {
2020
expect(env.FORCE_COLOR).toBe('0')
2121
})
2222

23+
test('triggers no colour mode based on --json flag', async () => {
24+
const launchCLI = vi.fn()
25+
const env = {} as any
26+
await runCLI({moduleURL: 'test', development: false}, launchCLI, ['--json'], env)
27+
expect(env.FORCE_COLOR).toBe('0')
28+
})
29+
30+
test('triggers no colour mode based on -j flag', async () => {
31+
const launchCLI = vi.fn()
32+
const env = {} as any
33+
await runCLI({moduleURL: 'test', development: false}, launchCLI, ['-j'], env)
34+
expect(env.FORCE_COLOR).toBe('0')
35+
})
36+
2337
test('triggers no colour mode based on NO_COLOR environment variable', async () => {
2438
const launchCLI = vi.fn()
2539
const env = {NO_COLOR: 'TRUE'} as any

packages/cli-kit/src/public/node/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ function setupEnvironmentVariables(
6262
function forceNoColor(argv: string[] = process.argv, env: NodeJS.ProcessEnv = process.env) {
6363
if (
6464
argv.includes('--no-color') ||
65+
argv.includes('--json') ||
66+
argv.includes('-j') ||
6567
isTruthy(env.NO_COLOR) ||
6668
isTruthy(env.SHOPIFY_FLAG_NO_COLOR) ||
6769
env.TERM === 'dumb'
@@ -142,7 +144,7 @@ export const globalFlags = {
142144
export const jsonFlag = {
143145
json: Flags.boolean({
144146
char: 'j',
145-
description: 'Output the result as JSON.',
147+
description: 'Output the result as JSON. Automatically disables color output.',
146148
hidden: false,
147149
default: false,
148150
env: environmentVariables.json,

packages/cli/README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ USAGE
555555
556556
FLAGS
557557
-c, --config=<value> [env: SHOPIFY_FLAG_APP_CONFIG] The name of the app configuration.
558-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
558+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
559559
--client-id=<value> [env: SHOPIFY_FLAG_CLIENT_ID] The Client ID of your app.
560560
--no-color [env: SHOPIFY_FLAG_NO_COLOR] Disable color output.
561561
--path=<value> [env: SHOPIFY_FLAG_PATH] The path to your function directory.
@@ -587,7 +587,7 @@ USAGE
587587
588588
FLAGS
589589
-c, --config=<value> [env: SHOPIFY_FLAG_APP_CONFIG] The name of the app configuration.
590-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
590+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
591591
-l, --log=<value> [env: SHOPIFY_FLAG_LOG] Specifies a log identifier to replay instead of selecting from a
592592
list. The identifier is provided in the output of `shopify app dev` and is the suffix of the
593593
log file name.
@@ -620,7 +620,7 @@ FLAGS
620620
-e, --export=<value> [env: SHOPIFY_FLAG_EXPORT] Name of the WebAssembly export to invoke.
621621
-i, --input=<value> [env: SHOPIFY_FLAG_INPUT] The input JSON to pass to the function. If omitted, standard input
622622
is used.
623-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
623+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
624624
--client-id=<value> [env: SHOPIFY_FLAG_CLIENT_ID] The Client ID of your app.
625625
--no-color [env: SHOPIFY_FLAG_NO_COLOR] Disable color output.
626626
--path=<value> [env: SHOPIFY_FLAG_PATH] The path to your function directory.
@@ -781,7 +781,7 @@ USAGE
781781
782782
FLAGS
783783
-c, --config=<value> [env: SHOPIFY_FLAG_APP_CONFIG] The name of the app configuration.
784-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
784+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
785785
--client-id=<value> [env: SHOPIFY_FLAG_CLIENT_ID] The Client ID of your app.
786786
--no-color [env: SHOPIFY_FLAG_NO_COLOR] Disable color output.
787787
--path=<value> [env: SHOPIFY_FLAG_PATH] The path to your app directory.
@@ -843,7 +843,7 @@ USAGE
843843
844844
FLAGS
845845
-c, --config=<value> [env: SHOPIFY_FLAG_APP_CONFIG] The name of the app configuration.
846-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
846+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
847847
-s, --store=<value>... [env: SHOPIFY_FLAG_STORE] Store URL. Must be an existing development or Shopify Plus sandbox
848848
store.
849849
--client-id=<value> [env: SHOPIFY_FLAG_CLIENT_ID] The Client ID of your app.
@@ -955,7 +955,7 @@ USAGE
955955
956956
FLAGS
957957
-c, --config=<value> [env: SHOPIFY_FLAG_APP_CONFIG] The name of the app configuration.
958-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
958+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
959959
--client-id=<value> [env: SHOPIFY_FLAG_CLIENT_ID] The Client ID of your app.
960960
--no-color [env: SHOPIFY_FLAG_NO_COLOR] Disable color output.
961961
--path=<value> [env: SHOPIFY_FLAG_PATH] The path to your app directory.
@@ -1783,7 +1783,7 @@ USAGE
17831783
$ shopify organization list [-j] [--no-color] [--verbose]
17841784
17851785
FLAGS
1786-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
1786+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
17871787
--no-color [env: SHOPIFY_FLAG_NO_COLOR] Disable color output.
17881788
--verbose [env: SHOPIFY_FLAG_VERBOSE] Increase the verbosity of the output.
17891789
@@ -2290,7 +2290,7 @@ FLAGS
22902290
-e, --environment=<value>... [env: SHOPIFY_FLAG_ENVIRONMENT] The environment to apply to the current command.
22912291
-f, --force [env: SHOPIFY_FLAG_FORCE] Force the duplicate operation to run without prompts or
22922292
confirmations.
2293-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
2293+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
22942294
-n, --name=<value> [env: SHOPIFY_FLAG_NAME] Name of the newly duplicated theme.
22952295
-s, --store=<value> [env: SHOPIFY_FLAG_STORE] Store URL. It can be the store prefix (example) or the full
22962296
myshopify.com URL (example.myshopify.com, https://example.myshopify.com).
@@ -2350,7 +2350,7 @@ USAGE
23502350
FLAGS
23512351
-d, --development [env: SHOPIFY_FLAG_DEVELOPMENT] Retrieve info from your development theme.
23522352
-e, --environment=<value>... [env: SHOPIFY_FLAG_ENVIRONMENT] The environment to apply to the current command.
2353-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
2353+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
23542354
-s, --store=<value> [env: SHOPIFY_FLAG_STORE] Store URL. It can be the store prefix (example) or the full
23552355
myshopify.com URL (example.myshopify.com, https://example.myshopify.com).
23562356
-t, --theme=<value> [env: SHOPIFY_FLAG_THEME_ID] Theme ID or name of the remote theme.
@@ -2429,7 +2429,7 @@ USAGE
24292429

24302430
FLAGS
24312431
-e, --environment=<value>... [env: SHOPIFY_FLAG_ENVIRONMENT] The environment to apply to the current command.
2432-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
2432+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
24332433
-s, --store=<value> [env: SHOPIFY_FLAG_STORE] Store URL. It can be the store prefix (example) or the full
24342434
myshopify.com URL (example.myshopify.com, https://example.myshopify.com).
24352435
--id=<value> [env: SHOPIFY_FLAG_ID] Only list theme with the given ID.
@@ -2589,7 +2589,7 @@ USAGE
25892589

25902590
FLAGS
25912591
-e, --environment=<value>... [env: SHOPIFY_FLAG_ENVIRONMENT] The environment to apply to the current command.
2592-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
2592+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color output.
25932593
-s, --store=<value> [env: SHOPIFY_FLAG_STORE] Store URL. It can be the store prefix (example) or the full
25942594
myshopify.com URL (example.myshopify.com, https://example.myshopify.com).
25952595
-t, --theme=<value> [env: SHOPIFY_FLAG_THEME_ID] Theme ID or name of the remote theme.
@@ -2702,7 +2702,8 @@ FLAGS
27022702
-d, --development [env: SHOPIFY_FLAG_DEVELOPMENT] Push theme files from your remote development
27032703
theme.
27042704
-e, --environment=<value>... [env: SHOPIFY_FLAG_ENVIRONMENT] The environment to apply to the current command.
2705-
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON.
2705+
-j, --json [env: SHOPIFY_FLAG_JSON] Output the result as JSON. Automatically disables color
2706+
output.
27062707
-l, --live [env: SHOPIFY_FLAG_LIVE] Push theme files from your remote live theme.
27072708
-n, --nodelete [env: SHOPIFY_FLAG_NODELETE] Prevent deleting remote files that don't exist
27082709
locally.

packages/cli/oclif.manifest.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@
15071507
"json": {
15081508
"allowNo": false,
15091509
"char": "j",
1510-
"description": "Output the result as JSON.",
1510+
"description": "Output the result as JSON. Automatically disables color output.",
15111511
"env": "SHOPIFY_FLAG_JSON",
15121512
"hidden": false,
15131513
"name": "json",
@@ -1595,7 +1595,7 @@
15951595
"json": {
15961596
"allowNo": false,
15971597
"char": "j",
1598-
"description": "Output the result as JSON.",
1598+
"description": "Output the result as JSON. Automatically disables color output.",
15991599
"env": "SHOPIFY_FLAG_JSON",
16001600
"hidden": false,
16011601
"name": "json",
@@ -1720,7 +1720,7 @@
17201720
"json": {
17211721
"allowNo": false,
17221722
"char": "j",
1723-
"description": "Output the result as JSON.",
1723+
"description": "Output the result as JSON. Automatically disables color output.",
17241724
"env": "SHOPIFY_FLAG_JSON",
17251725
"hidden": false,
17261726
"name": "json",
@@ -2366,7 +2366,7 @@
23662366
"json": {
23672367
"allowNo": false,
23682368
"char": "j",
2369-
"description": "Output the result as JSON.",
2369+
"description": "Output the result as JSON. Automatically disables color output.",
23702370
"env": "SHOPIFY_FLAG_JSON",
23712371
"hidden": false,
23722372
"name": "json",
@@ -2578,7 +2578,7 @@
25782578
"json": {
25792579
"allowNo": false,
25802580
"char": "j",
2581-
"description": "Output the result as JSON.",
2581+
"description": "Output the result as JSON. Automatically disables color output.",
25822582
"env": "SHOPIFY_FLAG_JSON",
25832583
"hidden": false,
25842584
"name": "json",
@@ -2964,7 +2964,7 @@
29642964
"json": {
29652965
"allowNo": false,
29662966
"char": "j",
2967-
"description": "Output the result as JSON.",
2967+
"description": "Output the result as JSON. Automatically disables color output.",
29682968
"env": "SHOPIFY_FLAG_JSON",
29692969
"hidden": false,
29702970
"name": "json",
@@ -5343,7 +5343,7 @@
53435343
"json": {
53445344
"allowNo": false,
53455345
"char": "j",
5346-
"description": "Output the result as JSON.",
5346+
"description": "Output the result as JSON. Automatically disables color output.",
53475347
"env": "SHOPIFY_FLAG_JSON",
53485348
"hidden": false,
53495349
"name": "json",
@@ -6314,7 +6314,7 @@
63146314
"json": {
63156315
"allowNo": false,
63166316
"char": "j",
6317-
"description": "Output the result as JSON.",
6317+
"description": "Output the result as JSON. Automatically disables color output.",
63186318
"env": "SHOPIFY_FLAG_JSON",
63196319
"hidden": false,
63206320
"name": "json",
@@ -6414,7 +6414,7 @@
64146414
"json": {
64156415
"allowNo": false,
64166416
"char": "j",
6417-
"description": "Output the result as JSON.",
6417+
"description": "Output the result as JSON. Automatically disables color output.",
64186418
"env": "SHOPIFY_FLAG_JSON",
64196419
"hidden": false,
64206420
"name": "json",
@@ -6620,7 +6620,7 @@
66206620
"json": {
66216621
"allowNo": false,
66226622
"char": "j",
6623-
"description": "Output the result as JSON.",
6623+
"description": "Output the result as JSON. Automatically disables color output.",
66246624
"env": "SHOPIFY_FLAG_JSON",
66256625
"hidden": false,
66266626
"name": "json",
@@ -7062,7 +7062,7 @@
70627062
"json": {
70637063
"allowNo": false,
70647064
"char": "j",
7065-
"description": "Output the result as JSON.",
7065+
"description": "Output the result as JSON. Automatically disables color output.",
70667066
"env": "SHOPIFY_FLAG_JSON",
70677067
"hidden": false,
70687068
"name": "json",
@@ -7456,7 +7456,7 @@
74567456
"json": {
74577457
"allowNo": false,
74587458
"char": "j",
7459-
"description": "Output the result as JSON.",
7459+
"description": "Output the result as JSON. Automatically disables color output.",
74607460
"env": "SHOPIFY_FLAG_JSON",
74617461
"hidden": false,
74627462
"name": "json",

0 commit comments

Comments
 (0)