Skip to content

Commit

Permalink
check if file already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloancheta authored and tavisrudd committed Dec 8, 2017
1 parent 1ebccdf commit 09792a5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,11 @@ export function buildArgs(commands = lazy, wrapMainHandler = wrapCommandHandler)
'init-stack-args',
description('initialize stack-args.yaml'),
(args) => args
.demandCommand(0, 0),
.demandCommand(0, 0)
.option('force', {
type: 'boolean', default: false,
description: description('Overwrite the current stack-args.yaml')
}),
wrapMainHandler(commands.initStackArgs))

.option('environment', environmentOpt)
Expand Down
17 changes: 14 additions & 3 deletions src/initStackArgs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs';
import {Arguments} from 'yargs';

export async function initStackArgs() : Promise<number> {
export async function initStackArgs(argv: Arguments) : Promise<number> {
// await configureAWS(argv.profile, argv.region);
// Here we import the File System module of node
const stackArgs = `# REQUIRED SETTINGS:
Expand Down Expand Up @@ -51,7 +52,17 @@ NotificationARNs:
# - make build # for example`


fs.writeFileSync('stack-args.yaml', stackArgs);
console.log("stack-args.yaml has been created!");
if (fs.existsSync('./stack-args.yaml') && !argv.force) {
console.log("stack-args.yaml already exists! Use --force to overwrite");
return 1
}
else {
fs.writeFileSync('stack-args.yaml', stackArgs);
if (argv.force) {
console.log("stack-args.yaml has been overwritten by a new one!");
} else {
console.log("stack-args.yaml has been created!");
}
}
return 0;
}
46 changes: 46 additions & 0 deletions stack-args.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# REQUIRED SETTINGS:
StackName: <string>
Template: <local file path or s3 path>
# optionally you can use the yaml pre-processor by prepending 'render:' to the filename
# Template: render:<local file path or s3 path>

# OPTIONAL SETTINGS:
# Region: <aws region name>
# Profile: <aws profile name>

# aws tags to apply to the stack
Tags:
# owner: <your name>
# environment: development
# project: <your project>
# lifetime: short

# stack parameters
Parameters:
# key1: value
# key2: value

# optional list. *Preferably empty*
Capabilities:
# - CAPABILITY_IAM
# - CAPABILITY_NAMED_IAM

NotificationARNs:
# - <sns arn>

# CloudFormation ServiceRole
# RoleARN: arn:aws:iam::<acount>:role/<rolename>

# TimeoutInMinutes: <number>

# OnFailure defaults to ROLLBACK
# OnFailure: 'ROLLBACK' | 'DELETE' | 'DO_NOTHING'

# StackPolicy: <local file path or s3 path>

# see http://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-stack.html#options
# ResourceTypes: <list of aws resource types allowed in the template>

# shell commands to run prior the cfn stack operation
# CommandsBefore:
# - make build # for example

0 comments on commit 09792a5

Please sign in to comment.