Skip to content

Commit

Permalink
feat(message): add spec version to message type
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Mar 30, 2018
1 parent 248951d commit 7839a12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/pact-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ cli
.option("-d, --dir <directory>", "Directory to which the pacts will be written.")
.option("--consumer <consumerName>", "Specify consumer name for written Pact files.")
.option("--provider <providerName>", "Specify provider name for written Pact files.")
.option("-s, --spec <n>", "The Pact specification version to use when writing the" +
" Pact files. Default is 3.", cli.INT)
.action((args: any, options: any) => pact.createMessage(options));

cli
Expand Down
9 changes: 9 additions & 0 deletions src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ export class Message {
"dir": "--pact_dir",
"consumer": "--consumer",
"provider": "--provider",
"spec": "--pact_specification_version",
};

constructor(options: MessageOptions) {
options = options || {};
options.pactFileWriteMode = options.pactFileWriteMode || "update";
options.spec = options.spec || 3;

checkTypes.assert.nonEmptyString(options.consumer, "Must provide the consumer name");
checkTypes.assert.nonEmptyString(options.provider, "Must provide the provider name");
checkTypes.assert.nonEmptyString(options.content, "Must provide message content");
checkTypes.assert.nonEmptyString(options.dir, "Must provide pact output dir");

if (options.spec) {
checkTypes.assert.number(options.spec);
checkTypes.assert.integer(options.spec);
checkTypes.assert.positive(options.spec);
}

if (options.dir) {
try {
fs.statSync(path.normalize(options.dir)).isDirectory();
Expand Down Expand Up @@ -90,4 +98,5 @@ export interface MessageOptions extends SpawnArguments {
consumer?: string;
provider?: string;
pactFileWriteMode?: "overwrite" | "update" | "merge";
spec?: number;
}

0 comments on commit 7839a12

Please sign in to comment.