Skip to content

Commit

Permalink
chore: made some minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
OlafConijn committed Feb 17, 2024
1 parent 75ab19d commit 3a38d6d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
15 changes: 13 additions & 2 deletions src/commands/create-organization-changeset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ChangeSetProvider } from '~change-set/change-set-provider';
import { TemplateRoot } from '~parser/parser';
import { GlobalState } from '~util/global-state';
import { AwsUtil } from '~util/aws-util';
import { yamlDump } from '~yaml-cfn/index';

const commandName = 'create-change-set <templateFile>';
const commandDescription = 'create change set that can be reviewed and executed later';
Expand All @@ -18,10 +19,16 @@ export class CreateChangeSetCommand extends BaseCliCommand<ICreateChangeSetComma
public addOptions(command: Command): void {
super.addOptions(command);
command.option('--change-set-name [change-set-name]', 'change set name');
command.option('--output <output>', 'serialization format used when printing change set. Either json or yaml.', 'json');
}

public async performCommand(command: ICreateChangeSetCommandArgs): Promise<void> {

if (!['json', 'yaml'].includes(command.output)) {
ConsoleUtil.LogError(`Invalid output format '${command.output}'. Must be either 'json' or 'yaml'.`);
return;
}

const template = await TemplateRoot.create(command.templateFile);
const state = await this.getState(command);

Expand All @@ -42,13 +49,17 @@ export class CreateChangeSetCommand extends BaseCliCommand<ICreateChangeSetComma

}

const contents = JSON.stringify(changeSet, null, 2);
ConsoleUtil.Out(contents);
if (command.output === 'json') {
ConsoleUtil.Out(JSON.stringify(changeSet, null, 2));
} else if (command.output === 'yaml') {
ConsoleUtil.Out(yamlDump(changeSet));
}
}
}

export interface ICreateChangeSetCommandArgs extends ICommandArgs {
masterAccountId?: any;
templateFile: string;
changeSetName?: string;
output?: 'json' | 'yaml';
}
18 changes: 8 additions & 10 deletions src/commands/print-changeset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ export class PrintChangeSetCommand extends BaseCliCommand<IPrintChangeSetCommand

public addOptions(command: Command): void {
super.addOptions(command);
command.option('--output <output>', 'the serialization format used when printing change set. Either json or yaml.', 'yaml');
command.option('--change-set-name [change-set-name]', 'change set name');
command.option('--output <output>', 'serialization format used when printing change set. Either json or yaml.', 'json');
}

public async performCommand(command: IPrintChangeSetCommandArgs): Promise<void> {
if (!['json', 'yaml'].includes(command.output)) {
ConsoleUtil.LogError(`Invalid output format '${command.output}'. Must be either 'json' or 'yaml'.`);
return;
}
const changeSetName = command.changeSetName;
const stateBucketName = await BaseCliCommand.GetStateBucketName(command.stateBucketName);
const provider = new ChangeSetProvider(stateBucketName);
Expand All @@ -34,18 +39,11 @@ export class PrintChangeSetCommand extends BaseCliCommand<IPrintChangeSetCommand
ConsoleUtil.LogError(`change set '${changeSetName}' not found.`);
return;
}
const template = new TemplateRoot(changeSetObj.template, './');
const state = await this.getState(command);

GlobalState.Init(state, template);

const binder = await this.getOrganizationBinder(template, state);
const tasks = binder.enumBuildTasks();
const changeSet = ChangeSetProvider.CreateChangeSet(tasks, changeSetName);
const changeSet = changeSetObj.changeSet;

if (command.output === 'json') {
ConsoleUtil.Out(JSON.stringify(changeSet, null, 2));
} else {
} else if (command.output === 'yaml') {
ConsoleUtil.Out(yamlDump(changeSet));
}

Expand Down

0 comments on commit 3a38d6d

Please sign in to comment.