@@ -12,7 +12,7 @@ import { MeowFlags, commonFlags } from '../flags'
1212
1313import type { Options } from 'meow'
1414
15- const { DRY_RUN_LABEL , REDACTED , SOCKET_CLI_SHOW_BANNER } = constants
15+ const { DRY_RUN_LABEL , REDACTED } = constants
1616
1717interface CliAlias {
1818 description : string
@@ -93,11 +93,8 @@ export async function meowWithSubcommands(
9393 }
9494 // ...else we provide basic instructions and help.
9595
96- // Temp disable until we clear the --json and --markdown usage
97- // Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
98- if ( constants . ENV [ SOCKET_CLI_SHOW_BANNER ] ) {
99- logger . log ( getAsciiHeader ( name ) )
100- }
96+ emitBanner ( name )
97+
10198 const cli = meow (
10299 `
103100 Usage
@@ -167,11 +164,8 @@ export function meowOrExit({
167164} ) {
168165 const command = `${ parentName } ${ config . commandName } `
169166 lastSeenCommand = command
170- // Temp disable until we clear the --json and --markdown usage.
171- // Lazily access constants.ENV[SOCKET_CLI_SHOW_BANNER].
172- if ( constants . ENV [ SOCKET_CLI_SHOW_BANNER ] ) {
173- logger . log ( getAsciiHeader ( command ) )
174- }
167+
168+ emitBanner ( command )
175169
176170 // This exits if .printHelp() is called either by meow itself or by us.
177171 const cli = meow ( {
@@ -189,6 +183,18 @@ export function meowOrExit({
189183 return cli
190184}
191185
186+ export function emitBanner ( name : string ) {
187+ // Print a banner at the top of each command.
188+ // This helps with brand recognition and marketing.
189+ // It also helps with debugging since it contains version and command details.
190+ // Note: print over stderr to preserve stdout for flags like --json and
191+ // --markdown. If we don't do this, you can't use --json in particular
192+ // and pipe the result to other tools. By emiting the banner over stderr
193+ // you can do something like `socket scan view xyz | jq | process`.
194+ // The spinner also emits over stderr for example.
195+ logger . error ( getAsciiHeader ( name ) )
196+ }
197+
192198function getAsciiHeader ( command : string ) {
193199 // Note: In tests we return <redacted> because otherwise snapshots will fail.
194200 // The '@rollup/plugin-replace' will replace "process.env['SOCKET_CLI_VERSION_HASH']".
@@ -208,7 +214,7 @@ function getAsciiHeader(command: string) {
208214 ? REDACTED
209215 : process
210216 . cwd ( )
211- . replace ( new RegExp ( `^${ escapeRegExp ( constants . homePath ) } ` , 'i' ) , '~/ ' )
217+ . replace ( new RegExp ( `^${ escapeRegExp ( constants . homePath ) } ` , 'i' ) , '~' )
212218 const body = `
213219 _____ _ _ /---------------
214220 | __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${ cliVersion }
0 commit comments