Skip to content

Commit 964cf76

Browse files
committed
Minor cleanup
1 parent 64ad940 commit 964cf76

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

src/commands/action/core/github.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ export class GitHub {
3030
switch (process.env['GITHUB_EVENT_NAME']) {
3131
case 'push':
3232
return this.prNumber ? 'diff' : 'main'
33-
case 'pull_request':
33+
case 'pull_request': {
3434
// This env variable needs to be set in the GitHub action.
3535
// Add this code below to GitHub action:
3636
// - steps:
3737
// - name: Get PR State
3838
// if: github.event_name == 'pull_request'
3939
// run: echo "EVENT_ACTION=${{ github.event.action }}" >> $GITHUB_ENV
4040
const eventAction = process.env['EVENT_ACTION']
41+
if (eventAction === 'opened' || eventAction === 'synchronize') {
42+
return 'diff'
43+
}
4144
if (!eventAction) {
4245
throw new Error('Missing event action')
4346
}
44-
if (['opened', 'synchronize'].includes(eventAction)) {
45-
return 'diff'
46-
} else {
47-
logger.log(`Pull request action: ${eventAction} is not supported`)
48-
process.exit()
49-
}
47+
logger.log(`Pull request action: ${eventAction} is not supported`)
48+
process.exit()
49+
}
5050
case 'issue_comment':
5151
return 'comment'
5252
default:

src/commands/cdxgen/cmd-cdxgen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { pluralize } from '@socketsecurity/registry/lib/words'
88

99
import { runCycloneDX } from './run-cyclonedx'
1010
import constants from '../../constants'
11+
import { isHelpFlag } from '../../utils/cmd'
1112
import { meowOrExit } from '../../utils/meow-with-subcommands'
1213
import { getFlagListOutput } from '../../utils/output-formatting'
1314

@@ -143,7 +144,7 @@ async function run(
143144
const cli = meowOrExit({
144145
allowUnknownFlags: true,
145146
// Don't let meow take over --help.
146-
argv: argv.filter(s => s !== '--help' && s !== '-h'),
147+
argv: argv.filter(isHelpFlag),
147148
config,
148149
importMeta,
149150
parentName

src/commands/cdxgen/run-cyclonedx.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ export async function runCycloneDX(yargv: any) {
6969
function argvToArray(argv: {
7070
[key: string]: boolean | null | number | string | Array<string | number>
7171
}): string[] {
72-
if (argv['help']) return ['--help']
72+
if (argv['help']) {
73+
return ['--help']
74+
}
7375
const result = []
7476
for (const { 0: key, 1: value } of Object.entries(argv)) {
75-
if (key === '_' || key === '--') continue
77+
if (key === '_' || key === '--') {
78+
continue
79+
}
7680
if (key === 'babel' || key === 'install-deps' || key === 'validate') {
7781
// cdxgen documents no-babel, no-install-deps, and no-validate flags so
7882
// use them when relevant.

src/utils/cmd.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const helpFlags = new Set(['--help', '-h'])
2+
13
export function cmdFlagsToString(args: string[]) {
24
const result = []
35
for (let i = 0, { length } = args; i < length; i += 1) {
@@ -18,3 +20,7 @@ export function cmdPrefixMessage(cmdName: string, text: string): string {
1820
const cmdPrefix = cmdName ? `${cmdName}: ` : ''
1921
return `${cmdPrefix}${text}`
2022
}
23+
24+
export function isHelpFlag(cmdArg: string) {
25+
return helpFlags.has(cmdArg)
26+
}

0 commit comments

Comments
 (0)