diff --git a/src/flags/orgFlags.ts b/src/flags/orgFlags.ts index 56a06fb0e..28aa3c9c6 100644 --- a/src/flags/orgFlags.ts +++ b/src/flags/orgFlags.ts @@ -26,9 +26,20 @@ export async function maybeGetOrg(input?: string | undefined): Promise => { - const org = await maybeGetOrg(input ?? (await getDefaultHub(false))); + let org: Org | undefined; + // user provided input, verify the org exits + if (input) { + org = await getOrgOrThrow(input); + } else { + // no input, check config for a default + const aliasOrUsername = await getDefaultHub(false); + // if there is a default, verify the org exists + if (aliasOrUsername) { + org = await getOrgOrThrow(aliasOrUsername); + } + } if (org) { - return ensureDevHub(org, input ?? org.getUsername()); + return ensureDevHub(org, org.getUsername()); } else { return undefined; } diff --git a/test/unit/flags/orgFlags.test.ts b/test/unit/flags/orgFlags.test.ts index c1db0c564..8d3b75c75 100644 --- a/test/unit/flags/orgFlags.test.ts +++ b/test/unit/flags/orgFlags.test.ts @@ -156,6 +156,10 @@ describe('org flags', () => { expect(e).to.have.property('name', 'NotADevHubError'); } }); + it('no input, no default hub, default target org => undefined', async () => { + await $$.stubConfig({ [OrgConfigProperties.TARGET_ORG]: testOrg.username }); + expect(await maybeGetHub()).to.be.undefined; + }); it('no input, no default => ok', async () => { await $$.stubConfig({}); expect(await maybeGetHub()).to.be.undefined;