From 930cebc310bbee53a086a1db317fb8e46d9d7439 Mon Sep 17 00:00:00 2001 From: Peter Murray <681306+peter-murray@users.noreply.github.com> Date: Wed, 3 Jul 2024 09:52:52 +0000 Subject: [PATCH] Adding detector settings into the CLI executables --- src/executable/cli.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/executable/cli.ts b/src/executable/cli.ts index 02e4f1f..d9ba411 100644 --- a/src/executable/cli.ts +++ b/src/executable/cli.ts @@ -20,6 +20,10 @@ program.option('-i --run-id ', 'Optional Run ID number for the activity program.option('--snapshot-exclude-file-name', 'exclude the file name in the dependency snapshot report. If false the name of the artifactor from the POM will be used, but any links in GitHub will not work.'); program.option('--snapshot-dependency-file-name ', 'optional override to specificy the path to the file that the snapshot will be associated with in the repository'); +program.option('--detector-name ', 'optional name of the detector that generated the snapshot'); +program.option('--detector-url ', 'optional URL of the detector that generated the snapshot, but not optional if you specify an detector-name'); +program.option('--detector-version ', 'optional version of the detector that generated the snapshot, but not optional if you specify an detector-name'); + program.parse(process.argv); const opts = program.opts(); @@ -44,6 +48,25 @@ async function execute() { process.exit(1); } + // If the detector-name is provided, then the other detector options become mandatory, check these early + let detector; + if (opts.detectorName) { + if (!opts.detectorUrl) { + console.error(`Error: detector-url is required when detector-name is provided\n`); + program.help({ error: true }); + } + + if (!opts.detectorVersion) { + console.error(`Error: detector-version is required when detector-name is provided\n`); + program.help({ error: true }); + } + detector = { + name: opts.detectorName, + url: opts.detectorUrl, + version: opts.detectorVersion, + } + } + try { // Build a fake GitHub Actions context so that values for the submission APIs can be retrieved const context = { @@ -71,8 +94,12 @@ async function execute() { manifestFile: opts.snapshotDependencyFileName, includeManifestFile: !opts.snapshotExcludeFileName, + detector: detector } + + + snapshot = await generateSnapshot(opts.directory, mvnConfig, snapshotConfig); } catch (err: any) {