UNPKG

2.19 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright (c) 2019, salesforce.com, inc.
4 * All rights reserved.
5 * Licensed under the BSD 3-Clause license.
6 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9const core_1 = require("@salesforce/core");
10const command_1 = require("@salesforce/command");
11const ToolbeltCommand_1 = require("./ToolbeltCommand");
12core_1.Messages.importMessagesDirectory(__dirname);
13const messages = core_1.Messages.loadMessages('salesforce-alm', 'reporterCommand');
14/**
15 * Support --resultfomat on commands. Useful for commands that can output different
16 * formats like human, csv, json, or different testing results like tap, etc.
17 */
18class ReporterCommand extends ToolbeltCommand_1.ToolbeltCommand {
19 static get flags() {
20 if (!this.flagsConfig) {
21 this.flagsConfig = {};
22 }
23 this.flagsConfig.resultformat = command_1.flags.enum(Object.assign({
24 char: 'r',
25 description: messages.getMessage('ResultFormatDescription'),
26 longDescription: messages.getMessage('ResultFormatLongDescription'),
27 options: ['human', 'csv', 'json']
28 }, this.resultFormatOptions));
29 return super.flags;
30 }
31 // Override the init to set this.json if the --resultformat (reporter) flag is json
32 async init() {
33 try {
34 const { flags } = this.parse({
35 flags: this.statics.flags,
36 args: this.statics.args
37 });
38 // Set json if the reporter is json
39 if (flags.resultformat === 'json' && !flags.json) {
40 this.argv.push('--json');
41 }
42 }
43 catch (err) {
44 /* parse can throw, so let super.init handle those */
45 }
46 return super.init();
47 }
48 // TypeScript does not yet have assertion-free polymorphic access to a class's static side from the instance side
49 get statics() {
50 return this.constructor;
51 }
52}
53ReporterCommand.resultFormatOptions = {};
54exports.ReporterCommand = ReporterCommand;
55
56//# sourceMappingURL=ReporterCommand.js.map