"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/src/lib/formatters/format-test-meta.ts" (20 Feb 2024, 2605 Bytes) of package /linux/misc/snyk-cli-1.1280.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 import chalk from 'chalk';
    2 import { rightPadWithSpaces } from '../../lib/right-pad';
    3 import { TestOptions, Options } from '../../lib/types';
    4 import { TestResult } from '../../lib/snyk-test/legacy';
    5 import { IacTestResponse } from '../../lib/snyk-test/iac-test-result';
    6 
    7 export function formatTestMeta(
    8   res: TestResult | IacTestResponse,
    9   options: Options & TestOptions,
   10 ): string {
   11   const padToLength = 19; // chars to align
   12   const packageManager = res.packageManager || options.packageManager;
   13   const targetFile = res.targetFile || res.displayTargetFile || options.file;
   14   const openSource = res.isPrivate ? 'no' : 'yes';
   15   const meta = res.org
   16     ? [chalk.bold(rightPadWithSpaces('Organization: ', padToLength)) + res.org]
   17     : [];
   18   meta.push(
   19     chalk.bold(rightPadWithSpaces('Package manager: ', padToLength)) +
   20       packageManager,
   21   );
   22   if (targetFile) {
   23     meta.push(
   24       chalk.bold(rightPadWithSpaces('Target file: ', padToLength)) + targetFile,
   25     );
   26   }
   27   if (res.projectName) {
   28     meta.push(
   29       chalk.bold(rightPadWithSpaces('Project name: ', padToLength)) +
   30         res.projectName,
   31     );
   32   }
   33   if (options.docker) {
   34     meta.push(
   35       chalk.bold(rightPadWithSpaces('Docker image: ', padToLength)) +
   36         options.path,
   37     );
   38 
   39     if (res.platform) {
   40       meta.push(
   41         chalk.bold(rightPadWithSpaces('Platform: ', padToLength)) +
   42           res.platform,
   43       );
   44     }
   45   } else {
   46     meta.push(
   47       chalk.bold(rightPadWithSpaces('Open source: ', padToLength)) + openSource,
   48     );
   49     meta.push(
   50       chalk.bold(rightPadWithSpaces('Project path: ', padToLength)) +
   51         options.path,
   52     );
   53   }
   54   if (res.payloadType !== 'k8sconfig') {
   55     const legacyRes: TestResult = res as TestResult;
   56     if (legacyRes.docker && legacyRes.docker.baseImage) {
   57       meta.push(
   58         chalk.bold(rightPadWithSpaces('Base image: ', padToLength)) +
   59           legacyRes.docker.baseImage,
   60       );
   61     }
   62 
   63     if (legacyRes.filesystemPolicy) {
   64       meta.push(
   65         chalk.bold(rightPadWithSpaces('Local Snyk policy: ', padToLength)) +
   66           chalk.green('found'),
   67       );
   68       if (
   69         legacyRes.ignoreSettings &&
   70         legacyRes.ignoreSettings.disregardFilesystemIgnores
   71       ) {
   72         meta.push(
   73           chalk.bold(
   74             rightPadWithSpaces('Local Snyk policy ignored: ', padToLength),
   75           ) + chalk.red('yes'),
   76         );
   77       }
   78     }
   79     if (legacyRes.licensesPolicy) {
   80       meta.push(
   81         chalk.bold(rightPadWithSpaces('Licenses: ', padToLength)) +
   82           chalk.green('enabled'),
   83       );
   84     }
   85   }
   86 
   87   return meta.join('\n');
   88 }