@@ -103,6 +103,41 @@ function findBestCommandMatch(
103103 return bestMatch
104104}
105105
106+ function getAsciiHeader ( command : string , orgFlag : string | undefined ) {
107+ // Note: In tests we return <redacted> because otherwise snapshots will fail.
108+ const { REDACTED } = constants
109+ const redacting = constants . ENV . VITEST
110+ const cliVersion = redacting
111+ ? REDACTED
112+ : constants . ENV . INLINED_SOCKET_CLI_VERSION_HASH
113+ const nodeVersion = redacting ? REDACTED : process . version
114+ const defaultOrg = getConfigValueOrUndef ( 'defaultOrg' )
115+ const readOnlyConfig = isReadOnlyConfig ( ) ? '*' : '.'
116+ const shownToken = redacting
117+ ? REDACTED
118+ : getVisibleTokenPrefix ( ) || '(not set)'
119+ const relCwd = redacting ? REDACTED : normalizePath ( tildify ( process . cwd ( ) ) )
120+ // Note: we must redact org when creating snapshots because dev machine probably
121+ // has a default org set but CI won't. Showing --org is fine either way.
122+ const orgPart = orgFlag
123+ ? `--org: ${ orgFlag } `
124+ : redacting
125+ ? 'org: <redacted>'
126+ : defaultOrg
127+ ? `default org: ${ defaultOrg } `
128+ : '(org not set)'
129+ // Note: We could draw these with ascii box art instead but I worry about
130+ // portability and paste-ability. "simple" ascii chars just work.
131+ const body = `
132+ _____ _ _ /---------------
133+ | __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${ cliVersion }
134+ |__ | ${ readOnlyConfig } | _| '_| -_| _| | Node: ${ nodeVersion } , API token: ${ shownToken } , ${ orgPart }
135+ |_____|___|___|_,_|___|_|.dev | Command: \`${ command } \`, cwd: ${ relCwd }
136+ ` . trim ( )
137+ // Note: logger will auto-append a newline.
138+ return ` ${ body } `
139+ }
140+
106141/**
107142 * Calculate Levenshtein distance between two strings for fuzzy matching.
108143 */
@@ -133,6 +168,18 @@ function shouldSuppressBanner(flags: Record<string, unknown>): boolean {
133168 return Boolean ( flags [ 'json' ] || flags [ 'markdown' ] || flags [ 'nobanner' ] )
134169}
135170
171+ export function emitBanner ( name : string , orgFlag : string | undefined ) {
172+ // Print a banner at the top of each command.
173+ // This helps with brand recognition and marketing.
174+ // It also helps with debugging since it contains version and command details.
175+ // Note: print over stderr to preserve stdout for flags like --json and
176+ // --markdown. If we don't do this, you can't use --json in particular
177+ // and pipe the result to other tools. By emitting the banner over stderr
178+ // you can do something like `socket scan view xyz | jq | process`.
179+ // The spinner also emits over stderr for example.
180+ logger . error ( getAsciiHeader ( name , orgFlag ) )
181+ }
182+
136183// For debugging. Whenever you call meowOrExit it will store the command here
137184// This module exports a getter that returns the current value.
138185let lastSeenCommand = ''
@@ -618,50 +665,3 @@ export function meowOrExit({
618665
619666 return cli
620667}
621-
622- export function emitBanner ( name : string , orgFlag : string | undefined ) {
623- // Print a banner at the top of each command.
624- // This helps with brand recognition and marketing.
625- // It also helps with debugging since it contains version and command details.
626- // Note: print over stderr to preserve stdout for flags like --json and
627- // --markdown. If we don't do this, you can't use --json in particular
628- // and pipe the result to other tools. By emitting the banner over stderr
629- // you can do something like `socket scan view xyz | jq | process`.
630- // The spinner also emits over stderr for example.
631- logger . error ( getAsciiHeader ( name , orgFlag ) )
632- }
633-
634- function getAsciiHeader ( command : string , orgFlag : string | undefined ) {
635- // Note: In tests we return <redacted> because otherwise snapshots will fail.
636- const { REDACTED } = constants
637- const redacting = constants . ENV . VITEST
638- const cliVersion = redacting
639- ? REDACTED
640- : constants . ENV . INLINED_SOCKET_CLI_VERSION_HASH
641- const nodeVersion = redacting ? REDACTED : process . version
642- const defaultOrg = getConfigValueOrUndef ( 'defaultOrg' )
643- const readOnlyConfig = isReadOnlyConfig ( ) ? '*' : '.'
644- const shownToken = redacting
645- ? REDACTED
646- : getVisibleTokenPrefix ( ) || '(not set)'
647- const relCwd = redacting ? REDACTED : normalizePath ( tildify ( process . cwd ( ) ) )
648- // Note: we must redact org when creating snapshots because dev machine probably
649- // has a default org set but CI won't. Showing --org is fine either way.
650- const orgPart = orgFlag
651- ? `--org: ${ orgFlag } `
652- : redacting
653- ? 'org: <redacted>'
654- : defaultOrg
655- ? `default org: ${ defaultOrg } `
656- : '(org not set)'
657- // Note: We could draw these with ascii box art instead but I worry about
658- // portability and paste-ability. "simple" ascii chars just work.
659- const body = `
660- _____ _ _ /---------------
661- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${ cliVersion }
662- |__ | ${ readOnlyConfig } | _| '_| -_| _| | Node: ${ nodeVersion } , API token: ${ shownToken } , ${ orgPart }
663- |_____|___|___|_,_|___|_|.dev | Command: \`${ command } \`, cwd: ${ relCwd }
664- ` . trim ( )
665- // Note: logger will auto-append a newline.
666- return ` ${ body } `
667- }
0 commit comments