@@ -6,9 +6,11 @@ import yargsParse from 'yargs-parser'
66import { pluralize } from '@socketsecurity/registry/lib/words'
77
88import { runCycloneDX } from './run-cyclonedx.ts'
9- import { CliCommandConfig } from '../../utils/meow-with-subcommands.ts'
9+ import { meowOrExit } from '../../utils/meow-with-subcommands.ts'
1010import { getFlagListOutput } from '../../utils/output-formatting.ts'
1111
12+ import type { CliCommandConfig } from '../../utils/meow-with-subcommands.ts'
13+
1214// TODO: convert yargs to meow. Or convert all the other things to yargs.
1315const toLower = ( arg : string ) => arg . toLowerCase ( )
1416const arrayToLower = ( arg : string [ ] ) => arg . map ( toLower )
@@ -126,16 +128,16 @@ export const cmdCdxgen = {
126128
127129async function run (
128130 argv : readonly string [ ] ,
129- _importMeta : ImportMeta ,
130- { parentName : _parentName } : { parentName : string }
131+ importMeta : ImportMeta ,
132+ { parentName } : { parentName : string }
131133) : Promise < void > {
132- // const cli = meowOrExit({
133- // allowUnknownFlags: true,
134- // argv,
135- // config,
136- // importMeta,
137- // parentName,
138- // })
134+ const cli = meowOrExit ( {
135+ allowUnknownFlags : true ,
136+ argv : argv . filter ( s => s !== '--help' && s !== '-h' ) , // Don't let meow take over --help
137+ config,
138+ importMeta,
139+ parentName
140+ } )
139141 //
140142 //
141143 // if (cli.input.length)
@@ -154,16 +156,18 @@ async function run(
154156 const unknown : Array < string > = yargv . _
155157 const { length : unknownLength } = unknown
156158 if ( unknownLength ) {
157- process . exitCode = 1
158159 console . error (
159160 `Unknown ${ pluralize ( 'argument' , unknownLength ) } : ${ yargv . _ . join ( ', ' ) } `
160161 )
162+ process . exitCode = 2 // bad input
161163 return
162164 }
163165
164166 if ( yargv . output === undefined ) {
165167 yargv . output = 'socket-cdx.json'
166168 }
167169
170+ if ( cli . flags [ 'dryRun' ] ) return console . log ( '[DryRun] Bailing now' )
171+
168172 await runCycloneDX ( yargv )
169173}
0 commit comments