Skip to content

Commit d1df8ef

Browse files
committed
add organization-id flag to suppress organization selection
1 parent 589cb8d commit d1df8ef

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

packages/app/src/cli/commands/app/init.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {validateFlavorValue, validateTemplateValue} from '../../services/init/va
77
import {MinimalOrganizationApp, Organization, OrganizationApp} from '../../models/organization.js'
88
import {appNamePrompt, createAsNewAppPrompt, selectAppPrompt} from '../../prompts/dev.js'
99
import {searchForAppsByNameFactory} from '../../services/dev/prompt-helpers.js'
10+
import {fetchOrganizations} from '../../services/dev/fetch.js'
1011
import {isValidName} from '../../models/app/validation/common.js'
1112
import {Flags} from '@oclif/core'
1213
import {globalFlags} from '@shopify/cli-kit/node/cli'
@@ -64,6 +65,12 @@ export default class Init extends AppLinkedCommand {
6465
env: 'SHOPIFY_FLAG_CLIENT_ID',
6566
exclusive: ['config'],
6667
}),
68+
'organization-id': Flags.string({
69+
hidden: false,
70+
description:
71+
'The organization ID. Your organization ID can be found in your Dev Dashboard URL: https://dev.shopify.com/dashboard/<organization-id>',
72+
env: 'SHOPIFY_FLAG_ORGANIZATION_ID',
73+
}),
6774
}
6875

6976
async run(): Promise<AppLinkedCommandOutput> {
@@ -93,7 +100,21 @@ export default class Init extends AppLinkedCommand {
93100
developerPlatformClient = selectedApp.developerPlatformClient ?? developerPlatformClient
94101
selectAppResult = {result: 'existing', app: selectedApp}
95102
} else {
96-
const org = await selectOrg()
103+
let org: Organization
104+
if (flags['organization-id']) {
105+
// If an organization-id is provided, fetch all organizations and find the matching one
106+
const orgs = await fetchOrganizations()
107+
const matchingOrg = orgs.find((organization) => organization.id === flags['organization-id'])
108+
if (!matchingOrg) {
109+
throw new AbortError(
110+
`Organization with ID ${flags['organization-id']} not found`,
111+
'Please verify the organization ID and try again. You can find your organization ID in your Dev Dashboard URL: https://dev.shopify.com/dashboard/<organization-id>',
112+
)
113+
}
114+
org = matchingOrg
115+
} else {
116+
org = await selectOrg()
117+
}
97118
developerPlatformClient = selectDeveloperPlatformClient({organization: org})
98119
const {organization, apps, hasMorePages} = await developerPlatformClient.orgAndApps(org.id)
99120
selectAppResult = await selectAppOrNewAppName(name, apps, hasMorePages, organization, developerPlatformClient)

packages/cli/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,8 @@ Create a new app project
581581

582582
```
583583
USAGE
584-
$ shopify app init [--client-id <value> | ] [--flavor <value>] [-n <value>] [--no-color] [-d
585-
npm|yarn|pnpm|bun] [-p <value>] [--template <value>] [--verbose]
584+
$ shopify app init [--client-id <value> | ] [--flavor <value>] [-n <value>] [--no-color] [--organization-id
585+
<value>] [-d npm|yarn|pnpm|bun] [-p <value>] [--template <value>] [--verbose]
586586
587587
FLAGS
588588
-d, --package-manager=<option> <options: npm|yarn|pnpm|bun>
@@ -592,6 +592,8 @@ FLAGS
592592
existing app. Using this flag avoids the app selection prompt.
593593
--flavor=<value> Which flavor of the given template to use.
594594
--no-color Disable color output.
595+
--organization-id=<value> The organization ID. Your organization ID can be found in your Dev Dashboard URL:
596+
https://dev.shopify.com/dashboard/<organization-id>.
595597
--template=<value> The app template. Accepts one of the following:
596598
- <reactRouter|remix|none>
597599
- Any GitHub repo with optional branch and subpath, e.g.,

packages/cli/oclif.manifest.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,15 @@
18961896
"name": "no-color",
18971897
"type": "boolean"
18981898
},
1899+
"organization-id": {
1900+
"description": "The organization ID. Your organization ID can be found in your Dev Dashboard URL: https://dev.shopify.com/dashboard/<organization-id>.",
1901+
"env": "SHOPIFY_FLAG_ORGANIZATION_ID",
1902+
"hasDynamicHelp": false,
1903+
"hidden": false,
1904+
"multiple": false,
1905+
"name": "organization-id",
1906+
"type": "option"
1907+
},
18991908
"package-manager": {
19001909
"char": "d",
19011910
"env": "SHOPIFY_FLAG_PACKAGE_MANAGER",

packages/create-app/oclif.manifest.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@
5151
"name": "no-color",
5252
"type": "boolean"
5353
},
54+
"organization-id": {
55+
"description": "The organization ID. Your organization ID can be found in your Dev Dashboard URL: https://dev.shopify.com/dashboard/<organization-id>.",
56+
"env": "SHOPIFY_FLAG_ORGANIZATION_ID",
57+
"hasDynamicHelp": false,
58+
"hidden": false,
59+
"multiple": false,
60+
"name": "organization-id",
61+
"type": "option"
62+
},
5463
"package-manager": {
5564
"char": "d",
5665
"env": "SHOPIFY_FLAG_PACKAGE_MANAGER",

0 commit comments

Comments
 (0)