diff --git a/src/cli/args.ts b/src/cli/args.ts index 750826a374..1f7623b732 100644 --- a/src/cli/args.ts +++ b/src/cli/args.ts @@ -68,7 +68,7 @@ export interface ArgsOptions { // (see the snyk-mvn-plugin or snyk-gradle-plugin) _doubleDashArgs: string[]; _: MethodArgs; - [key: string]: boolean | string | MethodArgs | string[]; // The two last types are for compatibility only + [key: string]: boolean | string | number | MethodArgs | string[]; // The two last types are for compatibility only } export function args(rawArgv: string[]): Args { @@ -227,6 +227,10 @@ export function args(rawArgv: string[]): Args { } } + if (argv.detectionDepth !== undefined) { + argv.detectionDepth = Number(argv.detectionDepth); + } + if (argv.skipUnresolved !== undefined) { if (argv.skipUnresolved === 'false') { argv.allowMissing = false; diff --git a/src/cli/index.ts b/src/cli/index.ts index d4f4ba2468..875429efb5 100755 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1,3 +1,4 @@ +#!/usr/bin/env node import 'source-map-support/register'; import * as Debug from 'debug'; import * as pathLib from 'path'; @@ -39,6 +40,7 @@ import { SupportedUserReachableFacingCliArgs, } from '../lib/types'; import { SarifFileOutputEmptyError } from '../lib/errors/empty-sarif-output-error'; +import { InvalidDetectionDepthValue } from '../lib/errors/invalid-detection-depth-value'; const debug = Debug('snyk'); const EXIT_CODES = { @@ -261,6 +263,14 @@ async function main() { throw new FileFlagBadInputError(); } + if ( + typeof args.options.detectionDepth !== 'undefined' && + (args.options.detectionDepth <= 0 || + Number.isNaN(args.options.detectionDepth)) + ) { + throw new InvalidDetectionDepthValue(); + } + validateUnsupportedSarifCombinations(args); validateOutputFile(args.options, 'json', new JsonFileOutputBadInputError()); diff --git a/src/lib/errors/invalid-detection-depth-value.ts b/src/lib/errors/invalid-detection-depth-value.ts new file mode 100644 index 0000000000..86cf00e118 --- /dev/null +++ b/src/lib/errors/invalid-detection-depth-value.ts @@ -0,0 +1,10 @@ +import { CustomError } from './custom-error'; + +export class InvalidDetectionDepthValue extends CustomError { + constructor() { + const msg = `Unsupported value for --detection-depth flag. Expected a positive integer.`; + super(msg); + this.code = 422; + this.userMessage = msg; + } +}