-
Notifications
You must be signed in to change notification settings - Fork 35
Add --context-file param to override cdk.context.json #576
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
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 |
---|---|---|
|
@@ -2,16 +2,18 @@ import * as os from 'os'; | |
import * as fs_path from 'path'; | ||
import { ToolkitError } from '@aws-cdk/toolkit-lib'; | ||
import * as fs from 'fs-extra'; | ||
import { Context, PROJECT_CONTEXT } from '../api/context'; | ||
import { Context, PROJECT_CONTEXT as DEFAULT_PROJECT_CONTEXT } from '../api/context'; | ||
import { Settings } from '../api/settings'; | ||
import type { Tag } from '../api/tags'; | ||
import { debug, warning } from '../logging'; | ||
import { info, debug, warning } from '../logging'; | ||
|
||
export const PROJECT_CONFIG = 'cdk.json'; | ||
export { PROJECT_CONTEXT } from '../api/context'; | ||
export const USER_DEFAULTS = '~/.cdk.json'; | ||
const CONTEXT_KEY = 'context'; | ||
|
||
let PROJECT_CONTEXT = DEFAULT_PROJECT_CONTEXT; | ||
export { PROJECT_CONTEXT }; | ||
|
||
export enum Command { | ||
LS = 'ls', | ||
LIST = 'list', | ||
|
@@ -122,6 +124,20 @@ export class Configuration { | |
public async load(): Promise<this> { | ||
const userConfig = await loadAndLog(USER_DEFAULTS); | ||
this._projectConfig = await loadAndLog(PROJECT_CONFIG); | ||
var userProjectContextFile = this.commandLineArguments.subSettings(['contextFile']).get([]); | ||
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 think you'll need to store the value as a class property |
||
// Check if file exists | ||
if ( | ||
userProjectContextFile && | ||
typeof userProjectContextFile === 'string' && | ||
fs.existsSync(expandHomeDir(userProjectContextFile)) | ||
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 don't think t the filepath should be considered relative to the user's home directory. It's also not what is done later on. |
||
) { | ||
info(`Using specified project context ${userProjectContextFile}`); | ||
PROJECT_CONTEXT = userProjectContextFile; | ||
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. see above |
||
} else { | ||
warning( | ||
`File ${userProjectContextFile} does not exist or is not a valid path. Using default: ${PROJECT_CONTEXT}`, | ||
); | ||
} | ||
this._projectContext = await loadAndLog(PROJECT_CONTEXT); | ||
|
||
// @todo cannot currently be disabled by cli users | ||
|
@@ -278,6 +294,7 @@ export function commandLineArgumentsToSettings(argv: Arguments): Settings { | |
build: argv.build, | ||
caBundlePath: argv.caBundlePath, | ||
context, | ||
contextFile: argv.contextFile, | ||
debug: argv.debug, | ||
tags, | ||
language: argv.language, | ||
|
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.
Let's not do this. It's going to be confusing if this value changes bases on whether
load()
has been called or not.You can just update the name of the variable to
DEFAULT_PROJECT_CONTEXT
everywhere, or maybe for now just update the docblock.