diff --git a/src/commands/audit-log/cmd-audit-log.test.mts b/src/commands/audit-log/cmd-audit-log.test.mts index df31b5d8a..2d8117c3e 100644 --- a/src/commands/audit-log/cmd-audit-log.test.mts +++ b/src/commands/audit-log/cmd-audit-log.test.mts @@ -78,10 +78,11 @@ describe('socket audit-log', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket audit-log\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) diff --git a/src/commands/config/cmd-config.test.mts b/src/commands/config/cmd-config.test.mts index a283ac997..a15a668f2 100644 --- a/src/commands/config/cmd-config.test.mts +++ b/src/commands/config/cmd-config.test.mts @@ -84,6 +84,7 @@ describe('socket config', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket\`, cwd: + \\x1b[31m\\xd7\\x1b[39m Could not parse Config as JSON" `) @@ -104,6 +105,7 @@ describe('socket config', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket\`, cwd: + \\x1b[31m\\xd7\\x1b[39m Could not parse Config as JSON" `) diff --git a/src/commands/json/cmd-json.test.mts b/src/commands/json/cmd-json.test.mts index 92c7ce6af..c7456cf57 100644 --- a/src/commands/json/cmd-json.test.mts +++ b/src/commands/json/cmd-json.test.mts @@ -51,6 +51,7 @@ describe('socket json', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket json\`, cwd: + \\x1b[34mi\\x1b[39m Target cwd: \\x1b[31m\\xd7\\x1b[39m Not found: " `) @@ -71,6 +72,7 @@ describe('socket json', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket json\`, cwd: + \\x1b[34mi\\x1b[39m Target cwd: \\x1b[31m\\xd7\\x1b[39m Not found: " `) @@ -97,6 +99,7 @@ describe('socket json', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket json\`, cwd: + \\x1b[34mi\\x1b[39m Target cwd: \\x1b[31m\\xd7\\x1b[39m Not found: " `) @@ -136,6 +139,7 @@ describe('socket json', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket json\`, cwd: + \\x1b[34mi\\x1b[39m Target cwd: \\x1b[32m\\u221a\\x1b[39m This is the contents of :" `) diff --git a/src/commands/manifest/cmd-manifest-conda.test.mts b/src/commands/manifest/cmd-manifest-conda.test.mts index bfa5efb6a..244a8bb0b 100644 --- a/src/commands/manifest/cmd-manifest-conda.test.mts +++ b/src/commands/manifest/cmd-manifest-conda.test.mts @@ -70,6 +70,7 @@ describe('socket manifest conda', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest conda\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Warning: This will approximate your Conda dependencies using PyPI. We do not yet officially support Conda. Use at your own risk." `) diff --git a/src/commands/organization/cmd-organization-policy-license.test.mts b/src/commands/organization/cmd-organization-policy-license.test.mts index 525295751..51561badf 100644 --- a/src/commands/organization/cmd-organization-policy-license.test.mts +++ b/src/commands/organization/cmd-organization-policy-license.test.mts @@ -66,10 +66,11 @@ describe('socket organization policy license', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy license\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - You need to be logged in to use this command. See \`socket login\`. (\\x1b[31mmissing API token\\x1b[39m) @@ -100,8 +101,10 @@ describe('socket organization policy license', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy license\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode" `) diff --git a/src/commands/organization/cmd-organization-policy-security.test.mts b/src/commands/organization/cmd-organization-policy-security.test.mts index 190b49745..dddcf6731 100644 --- a/src/commands/organization/cmd-organization-policy-security.test.mts +++ b/src/commands/organization/cmd-organization-policy-security.test.mts @@ -66,10 +66,11 @@ describe('socket organization policy security', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy security\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - You need to be logged in to use this command. See \`socket login\`. (\\x1b[31mmissing API token\\x1b[39m) diff --git a/src/commands/repository/cmd-repository-create.test.mts b/src/commands/repository/cmd-repository-create.test.mts index 63694f9da..68a80d337 100644 --- a/src/commands/repository/cmd-repository-create.test.mts +++ b/src/commands/repository/cmd-repository-create.test.mts @@ -67,10 +67,11 @@ describe('socket repository create', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository create\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) @@ -132,10 +133,11 @@ describe('socket repository create', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository create\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) diff --git a/src/commands/repository/cmd-repository-del.test.mts b/src/commands/repository/cmd-repository-del.test.mts index 6bf1ac16f..8bb959335 100644 --- a/src/commands/repository/cmd-repository-del.test.mts +++ b/src/commands/repository/cmd-repository-del.test.mts @@ -60,10 +60,11 @@ describe('socket repository del', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository del\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) @@ -125,10 +126,11 @@ describe('socket repository del', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository del\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) diff --git a/src/commands/repository/cmd-repository-list.test.mts b/src/commands/repository/cmd-repository-list.test.mts index e26a2c94f..5249d8acb 100644 --- a/src/commands/repository/cmd-repository-list.test.mts +++ b/src/commands/repository/cmd-repository-list.test.mts @@ -68,10 +68,11 @@ describe('socket repository list', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository list\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) @@ -123,10 +124,11 @@ describe('socket repository list', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository list\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) diff --git a/src/commands/repository/cmd-repository-update.test.mts b/src/commands/repository/cmd-repository-update.test.mts index 0d2667e02..5076fd523 100644 --- a/src/commands/repository/cmd-repository-update.test.mts +++ b/src/commands/repository/cmd-repository-update.test.mts @@ -65,10 +65,11 @@ describe('socket repository update', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository update\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) @@ -102,10 +103,11 @@ describe('socket repository update', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository update\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) diff --git a/src/commands/repository/cmd-repository-view.test.mts b/src/commands/repository/cmd-repository-view.test.mts index f2eb85a05..322c1e0bb 100644 --- a/src/commands/repository/cmd-repository-view.test.mts +++ b/src/commands/repository/cmd-repository-view.test.mts @@ -61,10 +61,11 @@ describe('socket repository view', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository view\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) @@ -126,10 +127,11 @@ describe('socket repository view', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket repository view\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) diff --git a/src/commands/scan/cmd-scan-create.mts b/src/commands/scan/cmd-scan-create.mts index fd8ed78ec..11b394cb8 100644 --- a/src/commands/scan/cmd-scan-create.mts +++ b/src/commands/scan/cmd-scan-create.mts @@ -3,6 +3,7 @@ import path from 'node:path' import { logger } from '@socketsecurity/registry/lib/logger' import { handleCreateNewScan } from './handle-create-new-scan.mts' +import { outputCreateNewScan } from './output-create-new-scan.mjs' import { suggestOrgSlug } from './suggest-org-slug.mts' import { suggestTarget } from './suggest_target.mts' import constants from '../../constants.mts' @@ -299,6 +300,18 @@ async function run( if (hasApiToken && !dryRun && interactive) { if (!orgSlug) { const suggestion = await suggestOrgSlug() + if (suggestion === undefined) { + await outputCreateNewScan( + { + ok: false, + message: 'Canceled by user', + cause: 'Org selector was canceled by user', + }, + outputKind, + false, + ) + return + } if (suggestion) { orgSlug = suggestion } diff --git a/src/commands/scan/cmd-scan-del.test.mts b/src/commands/scan/cmd-scan-del.test.mts index 1741ea4a3..e66133004 100644 --- a/src/commands/scan/cmd-scan-del.test.mts +++ b/src/commands/scan/cmd-scan-del.test.mts @@ -61,10 +61,11 @@ describe('socket scan del', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket scan del\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) diff --git a/src/commands/scan/cmd-scan-diff.test.mts b/src/commands/scan/cmd-scan-diff.test.mts index f2c89e4e1..2fa2a901c 100644 --- a/src/commands/scan/cmd-scan-diff.test.mts +++ b/src/commands/scan/cmd-scan-diff.test.mts @@ -71,10 +71,11 @@ describe('socket scan diff', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket scan diff\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Specify two Scan IDs. (\\x1b[31mmissing both Scan IDs\\x1b[39m) diff --git a/src/commands/scan/cmd-scan-github.mts b/src/commands/scan/cmd-scan-github.mts index cc0d607f2..70299f638 100644 --- a/src/commands/scan/cmd-scan-github.mts +++ b/src/commands/scan/cmd-scan-github.mts @@ -3,6 +3,7 @@ import path from 'node:path' import { logger } from '@socketsecurity/registry/lib/logger' import { handleCreateGithubScan } from './handle-create-github-scan.mts' +import { outputScanGithub } from './output-scan-github.mjs' import { suggestOrgSlug } from './suggest-org-slug.mts' import constants from '../../constants.mts' import { commonFlags, outputFlags } from '../../flags.mts' @@ -193,6 +194,17 @@ async function run( if (hasSocketApiToken && !dryRun && interactive) { if (!orgSlug) { const suggestion = await suggestOrgSlug() + if (suggestion === undefined) { + await outputScanGithub( + { + ok: false, + message: 'Canceled by user', + cause: 'Org selector was canceled by user', + }, + outputKind, + ) + return + } if (suggestion) { orgSlug = suggestion } diff --git a/src/commands/scan/cmd-scan-github.test.mts b/src/commands/scan/cmd-scan-github.test.mts index b1bf74139..b43e0e656 100644 --- a/src/commands/scan/cmd-scan-github.test.mts +++ b/src/commands/scan/cmd-scan-github.test.mts @@ -78,10 +78,11 @@ describe('socket scan github', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket scan github\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - This command requires an API token for access (\\x1b[31mmissing (try \`socket login\`)\\x1b[39m) @@ -117,8 +118,10 @@ describe('socket scan github', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket scan github\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode" `) diff --git a/src/commands/scan/cmd-scan-list.test.mts b/src/commands/scan/cmd-scan-list.test.mts index 30f1eec58..8b7fa16f2 100644 --- a/src/commands/scan/cmd-scan-list.test.mts +++ b/src/commands/scan/cmd-scan-list.test.mts @@ -72,10 +72,11 @@ describe('socket scan list', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket scan list\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mdot is an invalid org, most likely you forgot the org name here?\\x1b[39m) diff --git a/src/commands/scan/cmd-scan-metadata.test.mts b/src/commands/scan/cmd-scan-metadata.test.mts index ea58f3135..322f947cb 100644 --- a/src/commands/scan/cmd-scan-metadata.test.mts +++ b/src/commands/scan/cmd-scan-metadata.test.mts @@ -61,10 +61,11 @@ describe('socket scan metadata', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket scan metadata\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) diff --git a/src/commands/scan/cmd-scan-report.test.mts b/src/commands/scan/cmd-scan-report.test.mts index 6cfbeb1bf..d880a74fc 100644 --- a/src/commands/scan/cmd-scan-report.test.mts +++ b/src/commands/scan/cmd-scan-report.test.mts @@ -90,10 +90,11 @@ describe('socket scan report', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket scan report\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mdot is an invalid org, most likely you forgot the org name here?\\x1b[39m) diff --git a/src/commands/scan/cmd-scan-view.test.mts b/src/commands/scan/cmd-scan-view.test.mts index 723f5fef1..b9e439f34 100644 --- a/src/commands/scan/cmd-scan-view.test.mts +++ b/src/commands/scan/cmd-scan-view.test.mts @@ -64,10 +64,11 @@ describe('socket scan view', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket scan view\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mdot is an invalid org, most likely you forgot the org name here?\\x1b[39m) diff --git a/src/commands/scan/handle-create-github-scan.mts b/src/commands/scan/handle-create-github-scan.mts index 385e113be..f59e07041 100644 --- a/src/commands/scan/handle-create-github-scan.mts +++ b/src/commands/scan/handle-create-github-scan.mts @@ -1,8 +1,5 @@ -import { logger } from '@socketsecurity/registry/lib/logger' - import { createScanFromGithub } from './create-scan-from-github.mts' -import { failMsgWithBadge } from '../../utils/fail-msg-with-badge.mts' -import { serializeResultJson } from '../../utils/serialize-result-json.mts' +import { outputScanGithub } from './output-scan-github.mts' import type { OutputKind } from '../../types.mts' @@ -36,16 +33,5 @@ export async function handleCreateGithubScan({ repos: String(repos || ''), }) - if (outputKind === 'json') { - logger.log(serializeResultJson(result)) - return - } - - if (!result.ok) { - logger.fail(failMsgWithBadge(result.message, result.cause)) - return - } - - logger.log('') - logger.success('Finished!') + await outputScanGithub(result, outputKind) } diff --git a/src/commands/scan/output-scan-github.mts b/src/commands/scan/output-scan-github.mts new file mode 100644 index 000000000..2a16a583e --- /dev/null +++ b/src/commands/scan/output-scan-github.mts @@ -0,0 +1,24 @@ +import { logger } from '@socketsecurity/registry/lib/logger' + +import { failMsgWithBadge } from '../../utils/fail-msg-with-badge.mts' +import { serializeResultJson } from '../../utils/serialize-result-json.mts' + +import type { CResult, OutputKind } from '../../types.mts' + +export async function outputScanGithub( + result: CResult, + outputKind: OutputKind, +) { + if (outputKind === 'json') { + logger.log(serializeResultJson(result)) + return + } + + if (!result.ok) { + logger.fail(failMsgWithBadge(result.message, result.cause)) + return + } + + logger.log('') + logger.success('Finished!') +} diff --git a/src/commands/scan/suggest-org-slug.mts b/src/commands/scan/suggest-org-slug.mts index 6ff6ffd51..5ea850b1a 100644 --- a/src/commands/scan/suggest-org-slug.mts +++ b/src/commands/scan/suggest-org-slug.mts @@ -39,6 +39,9 @@ export async function suggestOrgSlug(): Promise { }, ], }) + if (proceed === undefined) { + return undefined + } if (proceed) { return proceed } diff --git a/src/commands/threat-feed/cmd-threat-feed.test.mts b/src/commands/threat-feed/cmd-threat-feed.test.mts index dc8966480..1e21ff36f 100644 --- a/src/commands/threat-feed/cmd-threat-feed.test.mts +++ b/src/commands/threat-feed/cmd-threat-feed.test.mts @@ -111,10 +111,11 @@ describe('socket threat-feed', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket threat-feed\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) @@ -164,10 +165,11 @@ describe('socket threat-feed', async () => { | __|___ ___| |_ ___| |_ | Socket.dev CLI ver |__ | * | _| '_| -_| _| | Node: , API token: , org: |_____|___|___|_,_|___|_|.dev | Command: \`socket threat-feed\`, cwd: + \\x1b[33m\\u203c\\x1b[39m Unable to determine the target org. Trying to auto-discover it now... \\x1b[34mi\\x1b[39m Note: you can run \`socket login\` to set a default org. You can also override it with the --org flag. - \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode + \\x1b[31m\\xd7\\x1b[39m Skipping auto-discovery of org in dry-run mode \\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again - Org name by default setting, --org, or auto-discovered (\\x1b[31mmissing\\x1b[39m) diff --git a/src/utils/check-input.mts b/src/utils/check-input.mts index d8fd164f4..d9032cef2 100644 --- a/src/utils/check-input.mts +++ b/src/utils/check-input.mts @@ -57,7 +57,6 @@ export function checkCommandInput( }), ) } else { - logger.error('') // Empty line between banner and error logger.fail(failMsgWithBadge('Input error', msg.join('\n'))) } diff --git a/src/utils/determine-org-slug.mts b/src/utils/determine-org-slug.mts index 7dc06a5cb..7dbe34199 100644 --- a/src/utils/determine-org-slug.mts +++ b/src/utils/determine-org-slug.mts @@ -50,6 +50,7 @@ export async function determineOrgSlug( logger.info( 'Note: you can run `socket login` to set a default org. You can also override it with the --org flag.', ) + logger.error('') // spacing in stderr if (dryRun) { logger.fail('Skipping auto-discovery of org in dry-run mode') } else { diff --git a/src/utils/meow-with-subcommands.mts b/src/utils/meow-with-subcommands.mts index 0748124fb..6b88d1085 100644 --- a/src/utils/meow-with-subcommands.mts +++ b/src/utils/meow-with-subcommands.mts @@ -199,6 +199,7 @@ export async function meowWithSubcommands( if (configOverrideResult?.ok === false) { emitBanner(name, orgFlag) + logger.error('') // spacing in stderr logger.fail(configOverrideResult.message) process.exitCode = 2 return @@ -401,6 +402,7 @@ ${isRootCommand ? ` $ ${name} scan create --json` : ''}${isRootCommand ? `\ // ...else we provide basic instructions and help. if (!cli2.flags['nobanner']) { emitBanner(name, orgFlag) + // meow will add newline so don't add stderr spacing here } if (!cli2.flags['help'] && cli2.flags['dryRun']) { process.exitCode = 0 @@ -446,6 +448,8 @@ export function meowOrExit({ if (!cli.flags['nobanner']) { emitBanner(command, String(cli.flags['org'] || '') || undefined) + // Add spacing in stderr. meow.help adds a newline too so we do it here + logger.error('') } // As per https://github.com/sindresorhus/meow/issues/178 @@ -525,6 +529,8 @@ function getAsciiHeader(command: string, orgFlag: string | undefined) { : defaultOrg ? `default org: ${defaultOrg}` : '(org not set)' + // Note: We could draw these with ascii box art instead but I worry about + // portability and paste-ability. "simple" ascii chars just work. const body = ` _____ _ _ /--------------- | __|___ ___| |_ ___| |_ | Socket.dev CLI ver ${cliVersion}