@sasjs/cli 4.6.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -358,7 +358,6 @@ var setupMocks = function () {
358
358
  jest
359
359
  .spyOn(configUtils, 'findTargetInConfiguration')
360
360
  .mockImplementation(function () { return Promise.resolve({ target: target, isLocal: true }); });
361
- jest.spyOn(process.logger, 'error');
362
361
  jest
363
362
  .spyOn(configUtils, 'getLocalConfig')
364
363
  .mockImplementation(function () { return Promise.resolve(config); });
@@ -73,10 +73,14 @@ function execute(target, sasjs, authConfig, source, logFolder, csvFile, streamLo
73
73
  _b = (0, internal_1.checkPredecessorDeadlock)(flows), predecessorDeadlock = _b.present, deadlockChain = _b.chain;
74
74
  if (predecessorDeadlock)
75
75
  return [2 /*return*/, reject('Circular dependency found in flows, cannot proceed\n- ' +
76
- deadlockChain.join(' -> '))];
76
+ deadlockChain.join(' -> '))
77
+ // job state poll options
78
+ // maxPollCount and pollInterval are set to 0 to use default polling options
79
+ // configured in @sasjs/adapter/src/api/viya/pollJobState.ts
80
+ ];
77
81
  pollOptions = {
78
- maxPollCount: 24 * 60 * 60,
79
- pollInterval: 1000,
82
+ maxPollCount: 0,
83
+ pollInterval: 0,
80
84
  streamLog: streamLog,
81
85
  logFolderPath: logFolderRealPath
82
86
  };
@@ -70,8 +70,8 @@ var saveToCsvModule = __importStar(require("../saveToCsv"));
70
70
  var normalizeFilePath = __importStar(require("../normalizeFilePath"));
71
71
  var csvColumns_1 = __importDefault(require("../csvColumns"));
72
72
  var pollOptions = {
73
- maxPollCount: 24 * 60 * 60,
74
- pollInterval: 1000,
73
+ maxPollCount: 0,
74
+ pollInterval: 0,
75
75
  streamLog: false,
76
76
  logFolderPath: 'fake/log/folder/path'
77
77
  };
@@ -274,7 +274,7 @@ function printHelpText() {
274
274
  "[2spaces]NOTE: Providing output flag (--output or -o) is optional. If present, CLI will immediately print out the response JSON. If value is provided, it will be treated as file path to save the response JSON.",
275
275
  "[2spaces]NOTE: Providing log flag (--log or -l) is optional. If present, CLI will fetch and save job log to local file.",
276
276
  "[2spaces]NOTE: Providing ignore warnings (--ignoreWarnings or -i) flag is optional. If present, CLI will return status '0', when the job state is warning.",
277
- "[2spaces]NOTE: Providing verbose (--verbose or -v) flag is optional. If present, CLI will log summary of every HTTP response."
277
+ "[2spaces]NOTE: Providing verbose (--verbose or -v) flag is optional. If present, CLI will log summary of every HTTP response. If set to 'bleached', CLI will log summary of every HTTP response without extra colors."
278
278
  ]
279
279
  },
280
280
  {
@@ -322,6 +322,17 @@ function printHelpText() {
322
322
  "[2spaces]NOTE: Providing outDirectory flag is optional. If not present, CLI will use save outputs into sasjsresults folder.",
323
323
  "[2spaces]NOTE: Providing force (--force or -f) flag is optional. If present, CLI will force command to finish running all tests and will not return an error code even when some are failing. Useful when the requirement is not to make CI Pipeline fail."
324
324
  ]
325
+ },
326
+ {
327
+ name: 'snippets',
328
+ title: 'snippets',
329
+ description: [
330
+ "Generates VS Code snippets from the Doxygen headers in the SAS Macros.",
331
+ "[2spaces]command example: sasjs snippets --outDirectory <folderPath> --target <targetName>",
332
+ "",
333
+ "[2spaces]NOTE: Providing <folderPath> is optional. If not present, generated snippets will be saved to 'sasjsresults/sasjs-macro-snippets.json' file.",
334
+ "[2spaces]NOTE: more information can be found here https://cli.sasjs.io/snippets/."
335
+ ]
325
336
  }
326
337
  ];
327
338
  aliases = [
@@ -1,13 +1,15 @@
1
- import { Target } from '@sasjs/utils';
1
+ import { AuthConfig, Target } from '@sasjs/utils';
2
+ import SASjs from '@sasjs/adapter/node';
2
3
  /**
3
4
  * Triggers existing job for execution on SASJS server.
5
+ * @param {object} sasjs - configuration object of SAS adapter.
4
6
  * @param target - SASJS server configuration.
5
7
  * @param jobPath - location of the job.
6
8
  * @param logFile - flag indicating if CLI should fetch and save log to provided file path. If filepath wasn't provided, {job}.log file will be created in current folder.
7
9
  * @param output - flag indicating if CLI should save output to provided file path.
8
10
  * @returns - promise that resolves into an object with log and output.
9
11
  */
10
- export declare function executeJobSasjs(target: Target, jobPath: string, logFile?: string, output?: string): Promise<{
12
+ export declare function executeJobSasjs(sasjs: SASjs, target: Target, jobPath: string, logFile?: string, output?: string, authConfig?: AuthConfig): Promise<{
11
13
  result: any;
12
14
  log: any;
13
- }>;
15
+ } | undefined>;
@@ -37,58 +37,44 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.executeJobSasjs = void 0;
40
- var node_1 = require("@sasjs/adapter/node");
41
- var utils_1 = require("../../../../utils");
42
- var utils_2 = require("../utils");
40
+ var utils_1 = require("../utils");
43
41
  /**
44
42
  * Triggers existing job for execution on SASJS server.
43
+ * @param {object} sasjs - configuration object of SAS adapter.
45
44
  * @param target - SASJS server configuration.
46
45
  * @param jobPath - location of the job.
47
46
  * @param logFile - flag indicating if CLI should fetch and save log to provided file path. If filepath wasn't provided, {job}.log file will be created in current folder.
48
47
  * @param output - flag indicating if CLI should save output to provided file path.
49
48
  * @returns - promise that resolves into an object with log and output.
50
49
  */
51
- function executeJobSasjs(target, jobPath, logFile, output) {
50
+ function executeJobSasjs(sasjs, target, jobPath, logFile, output, authConfig) {
52
51
  var _a;
53
52
  return __awaiter(this, void 0, void 0, function () {
54
- var authConfig, _b, sasjsApiClient, response;
55
- return __generator(this, function (_c) {
56
- switch (_c.label) {
57
- case 0: return [4 /*yield*/, (0, utils_1.isSasJsServerInServerMode)(target)];
53
+ var response;
54
+ return __generator(this, function (_b) {
55
+ switch (_b.label) {
56
+ case 0: return [4 /*yield*/, sasjs.executeJob({
57
+ _program: jobPath
58
+ }, target.appLoc, authConfig)];
58
59
  case 1:
59
- if (!(_c.sent())) return [3 /*break*/, 3];
60
- return [4 /*yield*/, (0, utils_1.getAuthConfig)(target)];
61
- case 2:
62
- _b = _c.sent();
63
- return [3 /*break*/, 4];
64
- case 3:
65
- _b = undefined;
66
- _c.label = 4;
67
- case 4:
68
- authConfig = _b;
69
- sasjsApiClient = new node_1.SASjsApiClient(new node_1.SasjsRequestClient(target.serverUrl, target.httpsAgentOptions));
70
- return [4 /*yield*/, sasjsApiClient.executeJob({
71
- _program: jobPath
72
- }, target.appLoc, authConfig)];
73
- case 5:
74
- response = _c.sent();
75
- if (!response) return [3 /*break*/, 9];
60
+ response = _b.sent();
61
+ if (!response) return [3 /*break*/, 5];
76
62
  // handle success
77
63
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.success('Job executed successfully!');
78
- if (!(!!logFile && response.log)) return [3 /*break*/, 7];
79
- return [4 /*yield*/, (0, utils_2.saveLog)(response.log, logFile, jobPath)
64
+ if (!(!!logFile && response.log)) return [3 /*break*/, 3];
65
+ return [4 /*yield*/, (0, utils_1.saveLog)(response.log, logFile, jobPath)
80
66
  // save output if it is present
81
67
  ];
82
- case 6:
83
- _c.sent();
84
- _c.label = 7;
85
- case 7:
86
- if (!(!!output && response.result)) return [3 /*break*/, 9];
87
- return [4 /*yield*/, (0, utils_2.saveOutput)(response.result, output)];
88
- case 8:
89
- _c.sent();
90
- _c.label = 9;
91
- case 9: return [2 /*return*/, response];
68
+ case 2:
69
+ _b.sent();
70
+ _b.label = 3;
71
+ case 3:
72
+ if (!(!!output && response.result)) return [3 /*break*/, 5];
73
+ return [4 /*yield*/, (0, utils_1.saveOutput)(response.result, output)];
74
+ case 4:
75
+ _b.sent();
76
+ _b.label = 5;
77
+ case 5: return [2 /*return*/, response];
92
78
  }
93
79
  });
94
80
  });
@@ -13,9 +13,8 @@ import { Target, AuthConfig } from '@sasjs/utils';
13
13
  * @param {boolean} ignoreWarnings - flag indicating if CLI should return status '0', when the job state is warning.
14
14
  * @param {string | undefined} source - an optional path to a JSON file containing macro variables.
15
15
  * @param {boolean} streamLog - a flag indicating if the logs should be streamed to the supplied log path during job execution. This is useful for getting feedback on long running jobs.
16
- * @param {boolean} verbose - enables verbose mode that logs summary of every HTTP response.
17
16
  */
18
- export declare function executeJobViya(sasjs: SASjs, authConfig: AuthConfig, jobPath: string, target: Target, waitForJob: boolean, output: string | boolean, logFile: string | undefined, statusFile: string | undefined, ignoreWarnings: boolean, source: string | undefined, streamLog: boolean, verbose: boolean): Promise<any>;
17
+ export declare function executeJobViya(sasjs: SASjs, authConfig: AuthConfig, jobPath: string, target: Target, waitForJob: boolean, output: string | boolean, logFile: string | undefined, statusFile: string | undefined, ignoreWarnings: boolean, source: string | undefined, streamLog: boolean): Promise<any>;
19
18
  /**
20
19
  * Gets job execution context name.
21
20
  * @param target - SAS server configuration.
@@ -62,9 +62,8 @@ var utils_3 = require("../utils");
62
62
  * @param {boolean} ignoreWarnings - flag indicating if CLI should return status '0', when the job state is warning.
63
63
  * @param {string | undefined} source - an optional path to a JSON file containing macro variables.
64
64
  * @param {boolean} streamLog - a flag indicating if the logs should be streamed to the supplied log path during job execution. This is useful for getting feedback on long running jobs.
65
- * @param {boolean} verbose - enables verbose mode that logs summary of every HTTP response.
66
65
  */
67
- function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output, logFile, statusFile, ignoreWarnings, source, streamLog, verbose) {
66
+ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output, logFile, statusFile, ignoreWarnings, source, streamLog) {
68
67
  var _a, _b;
69
68
  return __awaiter(this, void 0, void 0, function () {
70
69
  var pollOptions, result, startTime, contextName, macroVars, submittedJob, endTime, outputJson, currentDirPath, outputPath, folderPath, parentFolderPath, logObj, logUrl, logCount, logData, error_1;
@@ -73,8 +72,8 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
73
72
  switch (_c.label) {
74
73
  case 0:
75
74
  pollOptions = {
76
- maxPollCount: 24 * 60 * 60,
77
- pollInterval: 1000,
75
+ maxPollCount: 0,
76
+ pollInterval: 0,
78
77
  streamLog: streamLog,
79
78
  logFolderPath: logFile
80
79
  };
@@ -106,7 +105,7 @@ function executeJobViya(sasjs, authConfig, jobPath, target, waitForJob, output,
106
105
  }
107
106
  _c.label = 5;
108
107
  case 5: return [4 /*yield*/, sasjs
109
- .startComputeJob(jobPath, null, { contextName: contextName }, authConfig, waitForJob || !!logFile, pollOptions, true, macroVars === null || macroVars === void 0 ? void 0 : macroVars.macroVars, verbose || undefined)
108
+ .startComputeJob(jobPath, null, { contextName: contextName }, authConfig, waitForJob || !!logFile, pollOptions, true, macroVars === null || macroVars === void 0 ? void 0 : macroVars.macroVars)
110
109
  .catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
111
110
  var logData;
112
111
  var _a;
@@ -3,6 +3,9 @@ import { ReturnCode } from '../../types/command';
3
3
  import { TargetCommand } from '../../types/command/targetCommand';
4
4
  export declare class JobCommand extends TargetCommand {
5
5
  private jobSubCommands;
6
+ private verbose;
7
+ private sasjs;
8
+ private authConfig?;
6
9
  constructor(args: string[]);
7
10
  /**
8
11
  * Method responsible for command execution.
@@ -63,6 +63,7 @@ var utils_2 = require("../../utils");
63
63
  var getLogFilePath_1 = require("../../utils/getLogFilePath");
64
64
  var prefixAppLoc_1 = require("../../utils/prefixAppLoc");
65
65
  var execute_1 = require("./internal/execute");
66
+ var node_1 = __importDefault(require("@sasjs/adapter/node"));
66
67
  var JobSubCommand;
67
68
  (function (JobSubCommand) {
68
69
  JobSubCommand["Execute"] = "execute";
@@ -121,10 +122,10 @@ var executeParseOptions = {
121
122
  description: 'Flag indicating whether the logs should be streamed to a local file as the job executes.'
122
123
  },
123
124
  verbose: {
124
- type: 'boolean',
125
+ type: 'string',
125
126
  alias: 'v',
126
127
  default: false,
127
- description: 'If present, CLI will return status 0, 1 or 2 together with HTTP response summaries.'
128
+ description: "If present, CLI will return status 0, 1 or 2 together with HTTP response summaries. If set to 'bleached', HTTP response summaries will be logged without extra colors."
128
129
  }
129
130
  };
130
131
  var JobCommand = /** @class */ (function (_super) {
@@ -143,7 +144,10 @@ var JobCommand = /** @class */ (function (_super) {
143
144
  examples: examples,
144
145
  syntax: syntax
145
146
  }) || this;
147
+ _this.verbose = false;
148
+ _this.sasjs = new node_1.default();
146
149
  _this.jobSubCommands = jobSubCommands;
150
+ _this.verbose = getVerbose(args, _this.parsed.verbose);
147
151
  return _this;
148
152
  }
149
153
  /**
@@ -153,58 +157,78 @@ var JobCommand = /** @class */ (function (_super) {
153
157
  JobCommand.prototype.execute = function () {
154
158
  var _a;
155
159
  return __awaiter(this, void 0, void 0, function () {
156
- var target, returnStatusOnly, _b, _c, _d, _e;
160
+ var returnStatusOnly, target, sasjsAndAuthConfig, sasjs, authConfig, authConfigSas9, _b, _c, _d, _e;
157
161
  return __generator(this, function (_f) {
158
162
  switch (_f.label) {
159
- case 0: return [4 /*yield*/, this.getTargetInfo()
160
- // returnStatusOnly flag is deprecated and is left to display warning if used
161
- ];
162
- case 1:
163
- target = (_f.sent()).target;
163
+ case 0:
164
164
  returnStatusOnly = !!this.parsed.returnStatusOnly;
165
165
  if (returnStatusOnly) {
166
166
  process.logger.warn('--returnStatusOnly (-r) flag is deprecated.');
167
167
  }
168
+ return [4 /*yield*/, this.getTargetInfo()];
169
+ case 1:
170
+ target = (_f.sent()).target;
171
+ return [4 /*yield*/, (0, utils_2.getSASjsAndAuthConfig)(target).catch(function (err) {
172
+ var _a;
173
+ // handle getting instance of @sasjs/adapter and auth config failure
174
+ (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
175
+ return {
176
+ sasjs: (0, utils_2.getSASjs)(target),
177
+ authConfig: undefined,
178
+ authConfigSas9: undefined
179
+ };
180
+ })];
181
+ case 2:
182
+ sasjsAndAuthConfig = _f.sent();
183
+ sasjs = sasjsAndAuthConfig.sasjs;
184
+ authConfig = sasjsAndAuthConfig.authConfig;
185
+ authConfigSas9 = sasjsAndAuthConfig.authConfigSas9;
186
+ if (!sasjs || (!authConfig && !authConfigSas9)) {
187
+ return [2 /*return*/, command_1.ReturnCode.InternalError];
188
+ }
189
+ this.sasjs = sasjs;
190
+ this.sasjs.setVerboseMode(this.verbose);
191
+ this.authConfig = authConfig || authConfigSas9;
168
192
  _b = target.serverType;
169
193
  switch (_b) {
170
- case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
171
- case utils_1.ServerType.Sas9: return [3 /*break*/, 6];
172
- case utils_1.ServerType.Sasjs: return [3 /*break*/, 10];
194
+ case utils_1.ServerType.SasViya: return [3 /*break*/, 3];
195
+ case utils_1.ServerType.Sas9: return [3 /*break*/, 7];
196
+ case utils_1.ServerType.Sasjs: return [3 /*break*/, 11];
173
197
  }
174
- return [3 /*break*/, 14];
175
- case 2:
176
- if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 4];
177
- return [4 /*yield*/, this.executeJobViya(target)];
198
+ return [3 /*break*/, 15];
178
199
  case 3:
179
- _c = _f.sent();
180
- return [3 /*break*/, 5];
200
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 5];
201
+ return [4 /*yield*/, this.executeJobViya(target)];
181
202
  case 4:
203
+ _c = _f.sent();
204
+ return [3 /*break*/, 6];
205
+ case 5:
182
206
  _c = command_1.ReturnCode.InvalidCommand;
183
- _f.label = 5;
184
- case 5: return [2 /*return*/, _c];
185
- case 6:
186
- if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 8];
187
- return [4 /*yield*/, this.executeJobSas9(target)];
207
+ _f.label = 6;
208
+ case 6: return [2 /*return*/, _c];
188
209
  case 7:
189
- _d = _f.sent();
190
- return [3 /*break*/, 9];
210
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 9];
211
+ return [4 /*yield*/, this.executeJobSas9(target)];
191
212
  case 8:
213
+ _d = _f.sent();
214
+ return [3 /*break*/, 10];
215
+ case 9:
192
216
  _d = command_1.ReturnCode.InvalidCommand;
193
- _f.label = 9;
194
- case 9: return [2 /*return*/, _d];
195
- case 10:
217
+ _f.label = 10;
218
+ case 10: return [2 /*return*/, _d];
219
+ case 11:
196
220
  if (typeof this.parsed.jobPath !== 'string')
197
221
  return [2 /*return*/, command_1.ReturnCode.InvalidCommand];
198
- if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 12];
222
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 13];
199
223
  return [4 /*yield*/, this.executeJobSasjs(target)];
200
- case 11:
201
- _e = _f.sent();
202
- return [3 /*break*/, 13];
203
224
  case 12:
225
+ _e = _f.sent();
226
+ return [3 /*break*/, 14];
227
+ case 13:
204
228
  _e = command_1.ReturnCode.InvalidCommand;
205
- _f.label = 13;
206
- case 13: return [2 /*return*/, _e];
207
- case 14:
229
+ _f.label = 14;
230
+ case 14: return [2 /*return*/, _e];
231
+ case 15:
208
232
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error("This command is not supported for specified server type.\nPlease try again with a different server type.");
209
233
  return [2 /*return*/, command_1.ReturnCode.InternalError];
210
234
  }
@@ -228,7 +252,7 @@ var JobCommand = /** @class */ (function (_super) {
228
252
  output = ((_a = this.parsed.output) === null || _a === void 0 ? void 0 : _a.length)
229
253
  ? this.parsed.output
230
254
  : undefined;
231
- return [4 /*yield*/, (0, execute_1.executeJobSasjs)(target, jobPath, log, output)
255
+ return [4 /*yield*/, (0, execute_1.executeJobSasjs)(this.sasjs, target, jobPath, log, output, this.authConfig)
232
256
  .then(function () { return command_1.ReturnCode.Success; })
233
257
  .catch(function (err) {
234
258
  var _a;
@@ -251,9 +275,9 @@ var JobCommand = /** @class */ (function (_super) {
251
275
  JobCommand.prototype.executeJobSas9 = function (target) {
252
276
  var _a;
253
277
  return __awaiter(this, void 0, void 0, function () {
254
- var jobPath, log, source, output, _b, sasjs, authConfigSas9, userName, password, returnCode;
255
- return __generator(this, function (_c) {
256
- switch (_c.label) {
278
+ var jobPath, log, source, output, userName, password, returnCode;
279
+ return __generator(this, function (_b) {
280
+ switch (_b.label) {
257
281
  case 0:
258
282
  jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
259
283
  log = (0, getLogFilePath_1.getLogFilePath)(this.parsed.log, jobPath);
@@ -261,19 +285,10 @@ var JobCommand = /** @class */ (function (_super) {
261
285
  output = ((_a = this.parsed.output) === null || _a === void 0 ? void 0 : _a.length)
262
286
  ? this.parsed.output
263
287
  : undefined;
264
- return [4 /*yield*/, (0, utils_2.getSASjsAndAuthConfig)(target).catch(function (err) {
265
- var _a;
266
- // handle getting instance of @sasjs/adapter and auth config failure
267
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
268
- return { sasjs: undefined, authConfigSas9: undefined };
269
- })];
270
- case 1:
271
- _b = _c.sent(), sasjs = _b.sasjs, authConfigSas9 = _b.authConfigSas9;
272
- if (!authConfigSas9 || !sasjs)
273
- return [2 /*return*/, command_1.ReturnCode.InternalError];
274
- userName = authConfigSas9.userName;
275
- password = (0, utils_1.decodeFromBase64)(authConfigSas9.password);
276
- return [4 /*yield*/, (0, execute_1.executeJobSas9)(sasjs, { userName: userName, password: password }, jobPath, log, output, source)
288
+ this.authConfig = this.authConfig;
289
+ userName = this.authConfig.userName;
290
+ password = (0, utils_1.decodeFromBase64)(this.authConfig.password);
291
+ return [4 /*yield*/, (0, execute_1.executeJobSas9)(this.sasjs, { userName: userName, password: password }, jobPath, log, output, source)
277
292
  .then(function () { return command_1.ReturnCode.Success; })
278
293
  .catch(function (err) {
279
294
  var _a;
@@ -281,8 +296,8 @@ var JobCommand = /** @class */ (function (_super) {
281
296
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
282
297
  return command_1.ReturnCode.InternalError;
283
298
  })];
284
- case 2:
285
- returnCode = _c.sent();
299
+ case 1:
300
+ returnCode = _b.sent();
286
301
  return [2 /*return*/, returnCode];
287
302
  }
288
303
  });
@@ -296,16 +311,15 @@ var JobCommand = /** @class */ (function (_super) {
296
311
  JobCommand.prototype.executeJobViya = function (target) {
297
312
  var _a, _b;
298
313
  return __awaiter(this, void 0, void 0, function () {
299
- var jobPath, statusFile, log, ignoreWarnings, streamLog, verbose, source, wait, output, _c, sasjs, authConfig, returnCode;
300
- return __generator(this, function (_d) {
301
- switch (_d.label) {
314
+ var jobPath, statusFile, log, ignoreWarnings, streamLog, source, wait, output, returnCode;
315
+ return __generator(this, function (_c) {
316
+ switch (_c.label) {
302
317
  case 0:
303
318
  jobPath = (0, prefixAppLoc_1.prefixAppLoc)(target.appLoc, this.parsed.jobPath);
304
319
  statusFile = getStatusFilePath(this.parsed.statusFile);
305
320
  log = (0, getLogFilePath_1.getLogFilePath)(this.parsed.log, jobPath);
306
321
  ignoreWarnings = !!this.parsed.ignoreWarnings;
307
322
  streamLog = !!this.parsed.streamLog;
308
- verbose = !!this.parsed.verbose;
309
323
  source = this.parsed.source;
310
324
  wait = this.parsed.wait || !!log;
311
325
  output = ((_a = this.parsed.output) === null || _a === void 0 ? void 0 : _a.length)
@@ -313,19 +327,9 @@ var JobCommand = /** @class */ (function (_super) {
313
327
  : ((_b = this.parsed.output) === null || _b === void 0 ? void 0 : _b.length) === 0
314
328
  ? true
315
329
  : false;
316
- if (verbose && !wait)
330
+ if (!!this.verbose && !wait)
317
331
  wait = true;
318
- return [4 /*yield*/, (0, utils_2.getSASjsAndAuthConfig)(target).catch(function (err) {
319
- var _a;
320
- // handle getting instance of @sasjs/adapter and auth config failure
321
- (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Unable to execute job. Error fetching auth config: ', err);
322
- return { sasjs: undefined, authConfig: undefined };
323
- })];
324
- case 1:
325
- _c = _d.sent(), sasjs = _c.sasjs, authConfig = _c.authConfig;
326
- if (!authConfig || !sasjs)
327
- return [2 /*return*/, command_1.ReturnCode.InternalError];
328
- return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, authConfig, jobPath, target, wait, output, log, statusFile, ignoreWarnings, source, streamLog, verbose)
332
+ return [4 /*yield*/, (0, execute_1.executeJobViya)(this.sasjs, this.authConfig, jobPath, target, wait, output, log, statusFile, ignoreWarnings, source, streamLog)
329
333
  .then(function () { return command_1.ReturnCode.Success; })
330
334
  .catch(function (err) {
331
335
  var _a;
@@ -333,8 +337,8 @@ var JobCommand = /** @class */ (function (_super) {
333
337
  (_a = process.logger) === null || _a === void 0 ? void 0 : _a.error('Error executing job: ', err);
334
338
  return command_1.ReturnCode.InternalError;
335
339
  })];
336
- case 2:
337
- returnCode = _d.sent();
340
+ case 1:
341
+ returnCode = _c.sent();
338
342
  return [2 /*return*/, returnCode];
339
343
  }
340
344
  });
@@ -357,3 +361,20 @@ var getStatusFilePath = function (statusFileArg) {
357
361
  }
358
362
  return undefined;
359
363
  };
364
+ /**
365
+ * Determines verbose mode based on command arguments.
366
+ * @param args - command arguments.
367
+ * @param verboseArg - value of the verbose argument.
368
+ * @returns - verbose mode.
369
+ */
370
+ var getVerbose = function (args, verboseArg) {
371
+ var verboseArgPresent = args.includes('-v') || args.includes('--verbose');
372
+ if (verboseArgPresent) {
373
+ // if verboseArg, use the string as verbose mode(any strings not equal to
374
+ // 'bleached' will be ignored)
375
+ if (typeof verboseArg === 'string')
376
+ return verboseArg;
377
+ return true;
378
+ }
379
+ return false;
380
+ };
@@ -94,17 +94,17 @@ describe('executeJobViya', function () {
94
94
  it('should set streamLog to true when the flag is passed in', function () { return __awaiter(void 0, void 0, void 0, function () {
95
95
  return __generator(this, function (_a) {
96
96
  switch (_a.label) {
97
- case 0: return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, undefined, true, false)];
97
+ case 0: return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, undefined, true)];
98
98
  case 1:
99
99
  _a.sent();
100
100
  expect(sasjs.startComputeJob).toHaveBeenCalledWith('test/job', null, {
101
101
  contextName: 'Mock Context'
102
102
  }, mocks_1.mockAuthConfig, true, {
103
- maxPollCount: 24 * 60 * 60,
104
- pollInterval: 1000,
103
+ maxPollCount: 0,
104
+ pollInterval: 0,
105
105
  streamLog: true,
106
106
  logFolderPath: testLogsPath
107
- }, true, undefined, undefined);
107
+ }, true, undefined);
108
108
  return [4 /*yield*/, (0, utils_1.deleteFile)(testFilePath)];
109
109
  case 2:
110
110
  _a.sent();
@@ -115,62 +115,17 @@ describe('executeJobViya', function () {
115
115
  it('should set streamLog to false when the flag is false', function () { return __awaiter(void 0, void 0, void 0, function () {
116
116
  return __generator(this, function (_a) {
117
117
  switch (_a.label) {
118
- case 0: return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, undefined, false, false)];
118
+ case 0: return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, undefined, false)];
119
119
  case 1:
120
120
  _a.sent();
121
121
  expect(sasjs.startComputeJob).toHaveBeenCalledWith('test/job', null, {
122
122
  contextName: 'Mock Context'
123
123
  }, mocks_1.mockAuthConfig, true, {
124
- maxPollCount: 24 * 60 * 60,
125
- pollInterval: 1000,
124
+ maxPollCount: 0,
125
+ pollInterval: 0,
126
126
  streamLog: false,
127
127
  logFolderPath: testLogsPath
128
- }, true, undefined, undefined);
129
- return [4 /*yield*/, (0, utils_1.deleteFile)(testFilePath)];
130
- case 2:
131
- _a.sent();
132
- return [2 /*return*/];
133
- }
134
- });
135
- }); });
136
- it('should pass verbose as undefined when the flag is false', function () { return __awaiter(void 0, void 0, void 0, function () {
137
- return __generator(this, function (_a) {
138
- switch (_a.label) {
139
- case 0: return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, undefined, false, false)];
140
- case 1:
141
- _a.sent();
142
- expect(sasjs.startComputeJob).toHaveBeenCalledWith('test/job', null, {
143
- contextName: 'Mock Context'
144
- }, mocks_1.mockAuthConfig, true, {
145
- maxPollCount: 24 * 60 * 60,
146
- pollInterval: 1000,
147
- streamLog: false,
148
- logFolderPath: testLogsPath
149
- }, true, undefined, undefined);
150
- return [4 /*yield*/, (0, utils_1.deleteFile)(testFilePath)];
151
- case 2:
152
- _a.sent();
153
- return [2 /*return*/];
154
- }
155
- });
156
- }); });
157
- it('should pass verbose as true when the flag is true', function () { return __awaiter(void 0, void 0, void 0, function () {
158
- var verbose;
159
- return __generator(this, function (_a) {
160
- switch (_a.label) {
161
- case 0:
162
- verbose = true;
163
- return [4 /*yield*/, (0, execute_1.executeJobViya)(sasjs, mocks_1.mockAuthConfig, 'test/job', target, false, false, testLogsPath, testFilePath, false, undefined, false, verbose)];
164
- case 1:
165
- _a.sent();
166
- expect(sasjs.startComputeJob).toHaveBeenCalledWith('test/job', null, {
167
- contextName: 'Mock Context'
168
- }, mocks_1.mockAuthConfig, true, {
169
- maxPollCount: 24 * 60 * 60,
170
- pollInterval: 1000,
171
- streamLog: false,
172
- logFolderPath: testLogsPath
173
- }, true, undefined, verbose);
128
+ }, true, undefined);
174
129
  return [4 /*yield*/, (0, utils_1.deleteFile)(testFilePath)];
175
130
  case 2:
176
131
  _a.sent();
@@ -191,11 +146,15 @@ describe('executeJobSasjs', function () {
191
146
  });
192
147
  }); });
193
148
  it('should pass job pass as a _program parameter', function () { return __awaiter(void 0, void 0, void 0, function () {
194
- return __generator(this, function (_a) {
195
- switch (_a.label) {
196
- case 0: return [4 /*yield*/, (0, execute_1.executeJobSasjs)(target, 'test/job', path_1.default.join(process.projectDir, 'logs'))];
149
+ var _a, sasjs, authConfig;
150
+ return __generator(this, function (_b) {
151
+ switch (_b.label) {
152
+ case 0: return [4 /*yield*/, (0, utils_2.getSASjsAndAuthConfig)(target)];
197
153
  case 1:
198
- _a.sent();
154
+ _a = _b.sent(), sasjs = _a.sasjs, authConfig = _a.authConfig;
155
+ return [4 /*yield*/, (0, execute_1.executeJobSasjs)(sasjs, target, 'test/job', path_1.default.join(process.projectDir, 'logs'), undefined, authConfig)];
156
+ case 2:
157
+ _b.sent();
199
158
  expect(executeJobMock).toHaveBeenCalledWith({ _program: 'test/job' }, target.appLoc, undefined);
200
159
  return [2 /*return*/];
201
160
  }
@@ -599,7 +599,7 @@ var executeWrapper = function (_a) {
599
599
  var _b = _a.adapter, adapter = _b === void 0 ? sasjs : _b, jobPath = _a.jobPath, _c = _a.waitForJob, waitForJob = _c === void 0 ? false : _c, _d = _a.output, output = _d === void 0 ? false : _d, _e = _a.logFile, logFile = _e === void 0 ? undefined : _e, _f = _a.statusFile, statusFile = _f === void 0 ? undefined : _f, _g = _a.ignoreWarnings, ignoreWarnings = _g === void 0 ? false : _g, _h = _a.source, source = _h === void 0 ? undefined : _h, _j = _a.streamLog, streamLog = _j === void 0 ? false : _j;
600
600
  return __awaiter(void 0, void 0, void 0, function () {
601
601
  return __generator(this, function (_k) {
602
- return [2 /*return*/, (0, execute_1.executeJobViya)(adapter, authConfig, jobPath, target, waitForJob, output, logFile, statusFile, ignoreWarnings, source, streamLog, false)];
602
+ return [2 /*return*/, (0, execute_1.executeJobViya)(adapter, authConfig, jobPath, target, waitForJob, output, logFile, statusFile, ignoreWarnings, source, streamLog)];
603
603
  });
604
604
  });
605
605
  };