-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove CLI getAccountId util #1331
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { commaSeparatedValues } from '@hubspot/local-dev-lib/text'; | |
import { | ||
getConfigPath, | ||
getAccountConfig, | ||
getAccountId, | ||
loadConfigFromEnvironment, | ||
} from '@hubspot/local-dev-lib/config'; | ||
import { getOauthManager } from '@hubspot/local-dev-lib/oauth'; | ||
|
@@ -22,23 +23,24 @@ import { | |
getCwd, | ||
getExt, | ||
} from '@hubspot/local-dev-lib/path'; | ||
import { getAccountId, getCmsPublishMode } from './commonOpts'; | ||
import { getCmsPublishMode } from './commonOpts'; | ||
import { logError } from './errorHandlers/index'; | ||
|
||
export async function validateAccount( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that these validation checks weren't working correctly. I'm actually not sure if we should even keep them around. Now that I fixed these I'm starting to see them showing up. For example, I'm getting an error if I have env variables set and I try to run a CLI command without using I think these checks might be too aggressive, but curious to hear what others think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm yeah that seems unnecessary, you may still want to use your config file after setting env variables. The only thing we really need to check for is using |
||
options: Arguments<{ account?: string; accountId?: string }> | ||
options: Arguments<{ | ||
account?: string; | ||
accountId?: string; | ||
derivedAccountId?: number; | ||
providedAccountId?: string; | ||
}> | ||
): Promise<boolean> { | ||
const accountId = getAccountId(options); | ||
const { accountId: accountIdOption, account: accountOption } = options; | ||
const { derivedAccountId, providedAccountId } = options; | ||
const accountId = getAccountId(derivedAccountId); | ||
|
||
if (!accountId) { | ||
if (accountOption) { | ||
if (providedAccountId) { | ||
logger.error( | ||
`The account "${accountOption}" could not be found in the config` | ||
); | ||
} else if (accountIdOption) { | ||
logger.error( | ||
`The account "${accountIdOption}" could not be found in the config` | ||
`The account "${providedAccountId}" could not be found in the config` | ||
); | ||
} else { | ||
logger.error( | ||
|
@@ -48,7 +50,7 @@ export async function validateAccount( | |
return false; | ||
} | ||
|
||
if (accountOption && loadConfigFromEnvironment()) { | ||
if (providedAccountId && loadConfigFromEnvironment()) { | ||
throw new Error( | ||
'Cannot specify an account when environment variables are supplied. Please unset the environment variables or do not use the "--account" flag.' | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This util is just a wrapper around the local-dev-lib's
getAccountId
, except it also checks for any account env variables.Now that we have injectAccountIdMiddleware doing this same thing, we should be able to remove this util. Commands can get this same behavior by looking at
options.derivedAccountId
.The benefit of removing this is that it cuts down on the number of options for getting account ID's in the project.