Skip to content

Commit

Permalink
Merge pull request #1361 from sasjs/issue-1356
Browse files Browse the repository at this point in the history
feat(verbose): added verbose mode and deprecated --returnStatusOnly
  • Loading branch information
YuryShkoda authored Aug 3, 2023
2 parents 9e12a45 + 7452b4d commit 504cde5
Show file tree
Hide file tree
Showing 19 changed files with 455 additions and 181 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"access": "public"
},
"dependencies": {
"@sasjs/adapter": "4.5.1",
"@sasjs/adapter": "4.8.0",
"@sasjs/core": "4.46.3",
"@sasjs/lint": "2.3.1",
"@sasjs/utils": "3.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/add/addCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import { LogLevel } from '@sasjs/utils/logger'
import { ServerType, Target, HttpsAgentOptions } from '@sasjs/utils/types'

import SASjs, { CertificateError } from '@sasjs/adapter/node'
import SASjs from '@sasjs/adapter/node'
import { getNewAccessToken } from '../../utils/auth'
import { isSasJsServerInServerMode } from '../../utils'
import { createFile } from '@sasjs/utils'
Expand Down
5 changes: 1 addition & 4 deletions src/commands/compile/internal/compileTestFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ export async function copyTestMacroFiles(folderAbsolutePath: string) {
})
}

export const compileTestFlow = async (
target: Target,
config?: Configuration
) => {
export const compileTestFlow = async (target: Target) => {
if (
target.testConfig &&
Object.keys(target.testConfig).includes('testFolders')
Expand Down
5 changes: 1 addition & 4 deletions src/commands/compile/internal/spec/compileTestFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,7 @@ describe('compileTestFile', () => {

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

compileTestFlow(
testTarget as unknown as Target,
testConfig as unknown as Configuration
)
compileTestFlow(testTarget as unknown as Target)

expect(process.logger.warn).toHaveBeenCalledWith(expectedWarn)
})
Expand Down
8 changes: 4 additions & 4 deletions src/commands/help/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ export async function printHelpText() {
`[2spaces]* ${chalk.cyanBright(
'execute'
)} - triggers job for execution.`,
`[2spaces]command example: sasjs job execute /Public/job -t targetName --output ./outputFolder/output.json --returnStatusOnly --ignoreWarnings`,
`[2spaces]command example: sasjs job execute /Public/job -t targetName --wait --log ./logFolder/log.json -r -i`,
`[2spaces]command example: sasjs job execute /Public/job -t targetName --output ./outputFolder/output.json --ignoreWarnings --verbose`,
`[2spaces]command example: sasjs job execute /Public/job -t targetName --wait --log ./logFolder/log.json -i -v`,
``,
`[2spaces]NOTE: Providing wait flag (--wait or -w) is optional. If present, CLI will wait for job completion.`,
`[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.`,
`[2spaces]NOTE: Providing log flag (--log or -l) is optional. If present, CLI will fetch and save job log to local file.`,
`[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).`,
`[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.`
`[2spaces]NOTE: Providing ignore warnings (--ignoreWarnings or -i) flag is optional. If present, CLI will return status '0', when the job state is warning.`,
`[2spaces]NOTE: Providing verbose (--verbose or -v) flag is optional. If present, CLI will log summary of every HTTP response.`
]
},
{
Expand Down
23 changes: 11 additions & 12 deletions src/commands/job/internal/execute/sas9.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import path from 'path'
import SASjs from '@sasjs/adapter/node'
import { MacroVars, createFile, createFolder, folderExists } from '@sasjs/utils'
import { displayError, displaySuccess } from '../../../../utils/displayResult'
import { MacroVars } from '@sasjs/utils'
import { saveLog, saveOutput } from '../utils'
import { parseSourceFile } from '../../../../utils/parseSourceFile'

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

if (source) {
macroVars = await parseSourceFile(source)
}
// get macro variables
if (source) macroVars = await parseSourceFile(source)

// timestamp of the execution start
const startTime = new Date().getTime()

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

// timestamp of the execution end
const endTime = new Date().getTime()

if (result) {
if (result.status === 200) {
// handle success
process.logger.success(
`Job executed successfully! in ${(endTime - startTime) / 1000} seconds`
)

if (!!logFile && result.log) {
await saveLog(result.log, logFile, jobPath, false)
}
// save log if it is present
if (!!logFile && result.log) await saveLog(result.log, logFile, jobPath)

if (!!output && result.result) {
saveOutput(result.result, output, false)
}
// save output if it is present
if (!!output && result.result) await saveOutput(result.result, output)
} else {
// handle failure
process.logger.error(result.message)
process.logger.error(JSON.stringify(result.error, null, 2))
}
Expand Down
20 changes: 14 additions & 6 deletions src/commands/job/internal/execute/sasjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ import { Target } from '@sasjs/utils'
import { getAuthConfig, isSasJsServerInServerMode } from '../../../../utils'
import { saveLog, saveOutput } from '../utils'

/**
* Triggers existing job for execution on SASJS server.
* @param target - SASJS server configuration.
* @param jobPath - location of the job.
* @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.
* @param output - flag indicating if CLI should save output to provided file path.
* @returns - promise that resolves into an object with log and output.
*/
export async function executeJobSasjs(
target: Target,
jobPath: string,
logFile?: string,
output?: string
) {
// get authentication configuration if SASJS server is in server mode.
const authConfig = (await isSasJsServerInServerMode(target))
? await getAuthConfig(target)
: undefined
Expand All @@ -26,15 +35,14 @@ export async function executeJobSasjs(
)

if (response) {
// handle success
process.logger?.success('Job executed successfully!')

if (!!logFile && response.log) {
await saveLog(response.log, logFile, jobPath, false)
}
// save log if it is present
if (!!logFile && response.log) await saveLog(response.log, logFile, jobPath)

if (!!output && response.result) {
await saveOutput(response.result, output, false)
}
// save output if it is present
if (!!output && response.result) await saveOutput(response.result, output)
}

return response
Expand Down
Loading

0 comments on commit 504cde5

Please sign in to comment.