Skip to content

Commit

Permalink
fix: no default hub with default org
Browse files Browse the repository at this point in the history
fix no inputs, with default org to return undefined for hub org
  • Loading branch information
peternhale committed Jan 13, 2023
1 parent ecf6e0e commit c59d264
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/flags/orgFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@ export async function maybeGetOrg(input?: string | undefined): Promise<Org | und
}

export const maybeGetHub = async (input?: string): Promise<Org | undefined> => {
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;
}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/flags/orgFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c59d264

Please sign in to comment.