Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract the meow function #334

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/commands/action/cmd-action.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/socketcli.py
import meowOrExit from 'meow'

import { runAction } from './run-action.ts'
import { type CliCommandConfig } from '../../utils/meow-with-subcommands'
import { meowOrExit } from '../../utils/meow-with-subcommands'
import { getFlagListOutput } from '../../utils/output-formatting.ts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands'

const config: CliCommandConfig = {
commandName: 'action',
description: 'Socket action command', // GitHub Action ?
Expand Down Expand Up @@ -47,11 +48,11 @@ async function run(
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit(config.help(parentName, config), {
const cli = meowOrExit({
argv,
description: config.description,
config,
importMeta,
flags: config.flags
parentName
})

const githubEventBefore = String(cli.flags['githubEventBefore'] || '')
Expand Down
8 changes: 4 additions & 4 deletions src/commands/analytics/cmd-analytics.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import meowOrExit from 'meow'
import colors from 'yoctocolors-cjs'

import { displayAnalytics } from './display-analytics.ts'
import { commonFlags, outputFlags } from '../../flags'
import { AuthError } from '../../utils/errors'
import { meowOrExit } from '../../utils/meow-with-subcommands'
import { getFlagListOutput } from '../../utils/output-formatting'
import { getDefaultToken } from '../../utils/sdk.ts'

Expand Down Expand Up @@ -70,11 +70,11 @@ async function run(
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit(config.help(parentName, config), {
const cli = meowOrExit({
argv,
description: config.description,
config,
importMeta,
flags: config.flags
parentName
})

const { repo, scope, time } = cli.flags
Expand Down
14 changes: 7 additions & 7 deletions src/commands/audit-log/cmd-audit-log.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import meowOrExit from 'meow'
import colors from 'yoctocolors-cjs'

import { getAuditLog } from './get-audit-log.ts'
import { commonFlags, outputFlags } from '../../flags'
import { AuthError } from '../../utils/errors'
import { meowOrExit } from '../../utils/meow-with-subcommands'
import { getFlagListOutput } from '../../utils/output-formatting'
import { getDefaultToken } from '../../utils/sdk'

Expand Down Expand Up @@ -35,15 +35,15 @@ const config: CliCommandConfig = {
...commonFlags,
...outputFlags
},
help: (parentName, config) => `
help: (command, config) => `
Usage
$ ${parentName} ${config.commandName} <org slug>
$ ${command} <org slug>

Options
${getFlagListOutput(config.flags, 6)}

Examples
$ ${parentName} ${config.commandName} FakeOrg
$ ${command} FakeOrg
`
}

Expand All @@ -58,11 +58,11 @@ async function run(
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit(config.help(parentName, config), {
const cli = meowOrExit({
argv,
description: config.description,
config,
importMeta,
flags: config.flags
parentName
})

const type = String(cli.flags['type'] || '')
Expand Down
17 changes: 8 additions & 9 deletions src/commands/cdxgen/cmd-cdxgen.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// import meowOrExit from 'meow'
// import { meowOrExit } from '../../utils/meow-with-subcommands'
import process from 'node:process'

import yargsParse from 'yargs-parser'

import { pluralize } from '@socketsecurity/registry/lib/words'

import { runCycloneDX } from './run-cyclonedx.ts'
import { CliCommandConfig } from '../../utils/meow-with-subcommands.ts'
import { getFlagListOutput } from '../../utils/output-formatting.ts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.ts'

// TODO: convert yargs to meow. Or convert all the other things to yargs.
const toLower = (arg: string) => arg.toLowerCase()
const arrayToLower = (arg: string[]) => arg.map(toLower)
Expand Down Expand Up @@ -110,9 +109,9 @@ const config: CliCommandConfig = {
flags: {
// TODO: convert from yargsConfig
},
help: (parentName, config) => `
help: (command, config) => `
Usage
$ ${parentName} ${config.commandName} [options]
$ ${command} [options]

Options
${getFlagListOutput(config.flags, 6)}
Expand All @@ -130,12 +129,12 @@ async function run(
_importMeta: ImportMeta,
{ parentName: _parentName }: { parentName: string }
): Promise<void> {
// const cli = meowOrExit(config.help(parentName, config), {
// const cli = meowOrExit({
// allowUnknownFlags: true,
// argv,
// description: config.description,
// config,
// importMeta,
// // Note: we pass the args through so unknown args are allowed for this command
// flags: config.flags
// parentName,
// })
//
//
Expand Down
15 changes: 7 additions & 8 deletions src/commands/dependencies/cmd-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import meowOrExit from 'meow'

import { findDependencies } from './find-dependencies.ts'
import { commonFlags, outputFlags } from '../../flags'
import { meowOrExit } from '../../utils/meow-with-subcommands'
import { getFlagListOutput } from '../../utils/output-formatting'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.ts'
Expand All @@ -27,15 +26,15 @@ const config: CliCommandConfig = {
},
...outputFlags
},
help: (parentName, config) => `
help: (command, config) => `
Usage
${parentName} ${config.commandName}
${command}

Options
${getFlagListOutput(config.flags, 6)}

Examples
${parentName} ${config.commandName}
${command} --limit 20 --offset 10
`
}

Expand All @@ -50,11 +49,11 @@ async function run(
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit(config.help(parentName, config), {
const cli = meowOrExit({
argv,
description: config.description,
config,
importMeta,
flags: config.flags
parentName
})

// TODO: markdown flag is ignored
Expand Down
15 changes: 7 additions & 8 deletions src/commands/diff-scan/cmd-diff-scan-get.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import meowOrExit from 'meow'
import colors from 'yoctocolors-cjs'

import { getDiffScan } from './get-diff-scan.ts'
import { commonFlags, outputFlags } from '../../flags'
import { AuthError } from '../../utils/errors'
import { meowOrExit } from '../../utils/meow-with-subcommands'
import { getFlagListOutput } from '../../utils/output-formatting'
import { getDefaultToken } from '../../utils/sdk'

Expand Down Expand Up @@ -41,15 +41,15 @@ const config: CliCommandConfig = {
},
...outputFlags
},
help: (parentName, config) => `
help: (command, config) => `
Usage
$ ${parentName} ${config.commandName} <org slug> --before=<before> --after=<after>
$ ${command} <org slug> --before=<before> --after=<after>

Options
${getFlagListOutput(config.flags, 6)}

Examples
$ ${parentName} ${config.commandName} FakeCorp --before=aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 --after=aaa1aa1a-aaaa-1111-1a1a-1111111a11a1
$ ${command} FakeCorp --before=aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 --after=aaa1aa1a-aaaa-1111-1a1a-1111111a11a1
`
}

Expand All @@ -64,12 +64,11 @@ async function run(
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit(config.help(parentName, config), {
const cli = meowOrExit({
argv,
description: config.description,
config,
importMeta,
flags: config.flags,
allowUnknownFlags: false
parentName
})

const before = String(cli.flags['before'] || '')
Expand Down
13 changes: 6 additions & 7 deletions src/commands/fix/cmd-fix.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import meowOrExit from 'meow'

import { runFix } from './run-fix.ts'
import { meowOrExit } from '../../utils/meow-with-subcommands'
import { getFlagListOutput } from '../../utils/output-formatting.ts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.ts'
Expand All @@ -10,9 +9,9 @@ const config: CliCommandConfig = {
description: 'Fix "fixable" Socket alerts',
hidden: true,
flags: {},
help: (parentName, config) => `
help: (command, config) => `
Usage
$ ${parentName} ${config.commandName}
$ ${command}

Options
${getFlagListOutput(config.flags, 6)}
Expand All @@ -30,11 +29,11 @@ async function run(
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
meowOrExit(config.help(parentName, config), {
meowOrExit({
argv,
description: config.description,
config,
importMeta,
flags: config.flags
parentName
})

await runFix()
Expand Down
17 changes: 8 additions & 9 deletions src/commands/info/cmd-info.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import meowOrExit from 'meow'

import { getPackageInfo } from './get-package-info.ts'
import { commonFlags, outputFlags, validationFlags } from '../../flags'
import { InputError } from '../../utils/errors'
import { meowOrExit } from '../../utils/meow-with-subcommands'
import { getFlagListOutput } from '../../utils/output-formatting'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.ts'
Expand All @@ -16,16 +15,16 @@ const config: CliCommandConfig = {
...outputFlags,
...validationFlags
},
help: (parentName, config) => `
help: (command, config) => `
Usage
$ ${parentName} ${config.commandName} <name>
$ ${command} <name>

Options
${getFlagListOutput(config.flags, 6)}

Examples
$ ${parentName} ${config.commandName} webtorrent
$ ${parentName} ${config.commandName} [email protected]
$ ${command} webtorrent
$ ${command} [email protected]
`
}

Expand All @@ -40,11 +39,11 @@ async function run(
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit(config.help(parentName, config), {
const cli = meowOrExit({
argv,
description: config.description,
config,
importMeta,
flags: config.flags
parentName
})

if (cli.input.length > 1) {
Expand Down
16 changes: 8 additions & 8 deletions src/commands/login/cmd-login.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import meowOrExit from 'meow'

import isInteractive from '@socketregistry/is-interactive/index.cjs'

import { attemptLogin } from './attempt-login.ts'
import { InputError } from '../../utils/errors'
import { meowOrExit } from '../../utils/meow-with-subcommands'
import { getFlagListOutput } from '../../utils/output-formatting'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.ts'
Expand All @@ -22,17 +21,18 @@ const config: CliCommandConfig = {
description: 'Proxy to use when making connection to API server'
}
},
help: (parentName, config) => `
help: (command, config) => `
Usage
$ ${parentName} ${config.commandName}
$ ${command}

Logs into the Socket API by prompting for an API key

Options
${getFlagListOutput(config.flags, 6)}

Examples
$ ${parentName} ${config.commandName}
$ ${command}
$ ${command} --api-proxy=http://localhost:1234
`
}

Expand All @@ -47,11 +47,11 @@ async function run(
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit(config.help(parentName, config), {
const cli = meowOrExit({
argv,
description: config.description,
config,
importMeta,
flags: config.flags
parentName
})

if (!isInteractive()) {
Expand Down
Loading
Loading