UNPKG

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