Skip to content

Commit 504cde5

Browse files
authored
Merge pull request #1361 from sasjs/issue-1356
feat(verbose): added verbose mode and deprecated --returnStatusOnly
2 parents 9e12a45 + 7452b4d commit 504cde5

File tree

19 files changed

+455
-181
lines changed

19 files changed

+455
-181
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"access": "public"
5151
},
5252
"dependencies": {
53-
"@sasjs/adapter": "4.5.1",
53+
"@sasjs/adapter": "4.8.0",
5454
"@sasjs/core": "4.46.3",
5555
"@sasjs/lint": "2.3.1",
5656
"@sasjs/utils": "3.3.0",

src/commands/add/addCredential.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path'
22
import { LogLevel } from '@sasjs/utils/logger'
33
import { ServerType, Target, HttpsAgentOptions } from '@sasjs/utils/types'
44

5-
import SASjs, { CertificateError } from '@sasjs/adapter/node'
5+
import SASjs from '@sasjs/adapter/node'
66
import { getNewAccessToken } from '../../utils/auth'
77
import { isSasJsServerInServerMode } from '../../utils'
88
import { createFile } from '@sasjs/utils'

src/commands/compile/internal/compileTestFile.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ export async function copyTestMacroFiles(folderAbsolutePath: string) {
9595
})
9696
}
9797

98-
export const compileTestFlow = async (
99-
target: Target,
100-
config?: Configuration
101-
) => {
98+
export const compileTestFlow = async (target: Target) => {
10299
if (
103100
target.testConfig &&
104101
Object.keys(target.testConfig).includes('testFolders')

src/commands/compile/internal/spec/compileTestFile.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,7 @@ describe('compileTestFile', () => {
267267

268268
expect(process.logger.warn).toHaveBeenCalledWith(expectedWarn)
269269

270-
compileTestFlow(
271-
testTarget as unknown as Target,
272-
testConfig as unknown as Configuration
273-
)
270+
compileTestFlow(testTarget as unknown as Target)
274271

275272
expect(process.logger.warn).toHaveBeenCalledWith(expectedWarn)
276273
})

src/commands/help/help.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,14 @@ export async function printHelpText() {
289289
`[2spaces]* ${chalk.cyanBright(
290290
'execute'
291291
)} - triggers job for execution.`,
292-
`[2spaces]command example: sasjs job execute /Public/job -t targetName --output ./outputFolder/output.json --returnStatusOnly --ignoreWarnings`,
293-
`[2spaces]command example: sasjs job execute /Public/job -t targetName --wait --log ./logFolder/log.json -r -i`,
292+
`[2spaces]command example: sasjs job execute /Public/job -t targetName --output ./outputFolder/output.json --ignoreWarnings --verbose`,
293+
`[2spaces]command example: sasjs job execute /Public/job -t targetName --wait --log ./logFolder/log.json -i -v`,
294294
``,
295295
`[2spaces]NOTE: Providing wait flag (--wait or -w) is optional. If present, CLI will wait for job completion.`,
296296
`[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.`,
297297
`[2spaces]NOTE: Providing log flag (--log or -l) is optional. If present, CLI will fetch and save job log to local file.`,
298-
`[2spaces]NOTE: Providing return status only (--returnStatusOnly or -r) flag is optional. If present and wait flag is provided, CLI will job status only (0 = success, 1 = warning, 2 = error).`,
299-
`[2spaces]NOTE: Providing ignore warnings (--ignoreWarnings or -i) flag is optional. If present and return status only is provided, CLI will return status '0', when the job state is warning.`
298+
`[2spaces]NOTE: Providing ignore warnings (--ignoreWarnings or -i) flag is optional. If present, CLI will return status '0', when the job state is warning.`,
299+
`[2spaces]NOTE: Providing verbose (--verbose or -v) flag is optional. If present, CLI will log summary of every HTTP response.`
300300
]
301301
},
302302
{

src/commands/job/internal/execute/sas9.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import path from 'path'
21
import SASjs from '@sasjs/adapter/node'
3-
import { MacroVars, createFile, createFolder, folderExists } from '@sasjs/utils'
4-
import { displayError, displaySuccess } from '../../../../utils/displayResult'
2+
import { MacroVars } from '@sasjs/utils'
53
import { saveLog, saveOutput } from '../utils'
64
import { parseSourceFile } from '../../../../utils/parseSourceFile'
75

@@ -24,30 +22,31 @@ export async function executeJobSas9(
2422
) {
2523
let macroVars: MacroVars | null = null
2624

27-
if (source) {
28-
macroVars = await parseSourceFile(source)
29-
}
25+
// get macro variables
26+
if (source) macroVars = await parseSourceFile(source)
3027

28+
// timestamp of the execution start
3129
const startTime = new Date().getTime()
3230

3331
const result = await sasjs.request(jobPath, macroVars, config)
3432

33+
// timestamp of the execution end
3534
const endTime = new Date().getTime()
3635

3736
if (result) {
3837
if (result.status === 200) {
38+
// handle success
3939
process.logger.success(
4040
`Job executed successfully! in ${(endTime - startTime) / 1000} seconds`
4141
)
4242

43-
if (!!logFile && result.log) {
44-
await saveLog(result.log, logFile, jobPath, false)
45-
}
43+
// save log if it is present
44+
if (!!logFile && result.log) await saveLog(result.log, logFile, jobPath)
4645

47-
if (!!output && result.result) {
48-
saveOutput(result.result, output, false)
49-
}
46+
// save output if it is present
47+
if (!!output && result.result) await saveOutput(result.result, output)
5048
} else {
49+
// handle failure
5150
process.logger.error(result.message)
5251
process.logger.error(JSON.stringify(result.error, null, 2))
5352
}

src/commands/job/internal/execute/sasjs.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ import { Target } from '@sasjs/utils'
33
import { getAuthConfig, isSasJsServerInServerMode } from '../../../../utils'
44
import { saveLog, saveOutput } from '../utils'
55

6+
/**
7+
* Triggers existing job for execution on SASJS server.
8+
* @param target - SASJS server configuration.
9+
* @param jobPath - location of the job.
10+
* @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.
11+
* @param output - flag indicating if CLI should save output to provided file path.
12+
* @returns - promise that resolves into an object with log and output.
13+
*/
614
export async function executeJobSasjs(
715
target: Target,
816
jobPath: string,
917
logFile?: string,
1018
output?: string
1119
) {
20+
// get authentication configuration if SASJS server is in server mode.
1221
const authConfig = (await isSasJsServerInServerMode(target))
1322
? await getAuthConfig(target)
1423
: undefined
@@ -26,15 +35,14 @@ export async function executeJobSasjs(
2635
)
2736

2837
if (response) {
38+
// handle success
2939
process.logger?.success('Job executed successfully!')
3040

31-
if (!!logFile && response.log) {
32-
await saveLog(response.log, logFile, jobPath, false)
33-
}
41+
// save log if it is present
42+
if (!!logFile && response.log) await saveLog(response.log, logFile, jobPath)
3443

35-
if (!!output && response.result) {
36-
await saveOutput(response.result, output, false)
37-
}
44+
// save output if it is present
45+
if (!!output && response.result) await saveOutput(response.result, output)
3846
}
3947

4048
return response

0 commit comments

Comments
 (0)