Skip to content

Commit efbc2f0

Browse files
committed
Add --no-spinner support
1 parent 0d2bfb6 commit efbc2f0

2 files changed

Lines changed: 43 additions & 11 deletions

File tree

src/flags.mts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,47 +149,55 @@ export const commonFlags: MeowFlags = {
149149
config: {
150150
type: 'string',
151151
default: '',
152-
hidden: true,
153152
description: 'Override the local config with this JSON',
153+
hidden: true,
154154
},
155155
dryRun: {
156156
type: 'boolean',
157157
default: false,
158-
// Only show in root command.
159-
hidden: true,
160158
description:
161159
'Do input validation for a command and exit 0 when input is ok',
160+
// Only show in root command.
161+
hidden: true,
162162
},
163163
help: {
164164
type: 'boolean',
165165
default: false,
166166
shortFlag: 'h',
167-
hidden: true,
168167
description: 'Print this help',
168+
hidden: true,
169169
},
170170
maxOldSpaceSize: {
171171
type: 'number',
172172
get default() {
173173
return getMaxOldSpaceSizeFlag()
174174
},
175-
hidden: true,
176175
description: `Set Node's V8 ${terminalLink('--max-old-space-size', 'https://nodejs.org/api/cli.html#--max-old-space-sizesize-in-mib')} option`,
176+
hidden: true,
177177
},
178178
maxSemiSpaceSize: {
179179
type: 'number',
180180
get default() {
181181
return getMaxSemiSpaceSizeFlag()
182182
},
183-
hidden: true,
184183
description: `Set Node's V8 ${terminalLink('--max-semi-space-size', 'https://nodejs.org/api/cli.html#--max-semi-space-sizesize-in-mib')} option`,
184+
hidden: true,
185185
},
186+
187+
// I know this would be `--no-banner` but that doesn't work with cdxgen.
188+
// Mostly for internal usage anyways.
186189
nobanner: {
187-
// I know this would be `--no-banner` but that doesn't work with cdxgen.
188-
// Mostly for internal usage anyways.
189190
type: 'boolean',
190191
default: false,
191-
hidden: true,
192192
description: 'Hide the Socket banner',
193+
hidden: true,
194+
},
195+
// Hidden to allow custom documenting of the negated `--no-spinner` variant.
196+
spinner: {
197+
type: 'boolean',
198+
default: true,
199+
description: 'Hide the console spinner',
200+
hidden: true,
193201
},
194202
}
195203

src/utils/meow-with-subcommands.mts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { logger } from '@socketsecurity/registry/lib/logger'
77
import { hasOwn, toSortedObject } from '@socketsecurity/registry/lib/objects'
88
import { normalizePath } from '@socketsecurity/registry/lib/path'
99
import { naturalCompare } from '@socketsecurity/registry/lib/sorts'
10+
import { Spinner } from '@socketsecurity/registry/lib/spinner'
1011
import {
1112
indentString,
1213
trimNewlines,
@@ -24,7 +25,7 @@ import { commonFlags } from '../flags.mts'
2425
import { getVisibleTokenPrefix } from './sdk.mts'
2526
import { tildify } from './tildify.mts'
2627

27-
import type { MeowFlags } from '../flags.mts'
28+
import type { MeowFlag, MeowFlags } from '../flags.mts'
2829
import type { Options, Result } from 'meow'
2930

3031
export interface CliAlias {
@@ -300,8 +301,14 @@ export async function meowWithSubcommands(
300301
booleanDefault: undefined,
301302
})
302303

304+
const noSpinner = cli1.flags['spinner'] === false
303305
const orgFlag = String(cli1.flags['org'] || '') || undefined
304306

307+
// Use CI spinner style when --no-spinner is passed.
308+
if (noSpinner) {
309+
constants.spinner.spinner = Spinner.spinners['ci']!
310+
}
311+
305312
// Hard override the config if instructed to do so.
306313
// The env var overrides the --flag, which overrides the persisted config
307314
// Also, when either of these are used, config updates won't persist.
@@ -501,7 +508,17 @@ export async function meowWithSubcommands(
501508
lines.push('')
502509
}
503510
lines.push(
504-
` ${getFlagListOutput(flags, { indent: HELP_INDENT, padName: HELP_PAD_NAME })}`,
511+
` ${getFlagListOutput(
512+
{
513+
...flags,
514+
// Explicitly document the negated --no-spinner variant.
515+
noSpinner: {
516+
...flags['spinner'],
517+
hidden: false,
518+
} as MeowFlag,
519+
},
520+
{ indent: HELP_INDENT, padName: HELP_PAD_NAME },
521+
)}`,
505522
)
506523
if (isRootCommand) {
507524
lines.push(
@@ -604,6 +621,13 @@ export function meowOrExit({
604621
importMeta,
605622
})
606623

624+
const noSpinner = cli.flags['spinner'] === false
625+
626+
// Use CI spinner style when --no-spinner is passed.
627+
if (noSpinner) {
628+
constants.spinner.spinner = Spinner.spinners['ci']!
629+
}
630+
607631
if (!shouldSuppressBanner(cli.flags)) {
608632
const orgFlag = String(cli.flags['org'] || '').trim() || undefined
609633
emitBanner(command, orgFlag)

0 commit comments

Comments
 (0)