Skip to content

Commit 34e078e

Browse files
committed
Use even more requirements.json
1 parent 1a65149 commit 34e078e

File tree

16 files changed

+241
-170
lines changed

16 files changed

+241
-170
lines changed

requirements.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"quota": 100,
2525
"permissions": ["packages:list"]
2626
},
27+
"optimize": {
28+
"quota": 100,
29+
"permissions": ["packages:list"]
30+
},
2731
"organization:dependencies": {
2832
"quota": 1,
2933
"permissions": []

src/commands/analytics/cmd-analytics.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const hidden = false
2525
export const cmdAnalytics = {
2626
description,
2727
hidden,
28-
run: run,
28+
run,
2929
}
3030

3131
async function run(

src/commands/config/cmd-config-auto.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'
1717

1818
const { DRY_RUN_BAILING_NOW } = constants
1919

20+
export const CMD_NAME = 'auto'
21+
2022
const description =
2123
'Automatically discover and set the correct value config item'
2224

@@ -34,7 +36,7 @@ async function run(
3436
{ parentName }: { parentName: string },
3537
): Promise<void> {
3638
const config: CliCommandConfig = {
37-
commandName: 'auto',
39+
commandName: CMD_NAME,
3840
description,
3941
hidden,
4042
flags: {

src/commands/config/cmd-config-set.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'
1717

1818
const { DRY_RUN_BAILING_NOW } = constants
1919

20+
export const CMD_NAME = 'set'
21+
2022
const description = 'Update the value of a local CLI config item'
2123

2224
const hidden = false
@@ -33,7 +35,7 @@ async function run(
3335
{ parentName }: { parentName: string },
3436
): Promise<void> {
3537
const config: CliCommandConfig = {
36-
commandName: 'set',
38+
commandName: CMD_NAME,
3739
description,
3840
hidden,
3941
flags: {

src/commands/config/cmd-config-unset.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import type { CliCommandConfig } from '../../utils/meow-with-subcommands.mts'
1717

1818
const { DRY_RUN_BAILING_NOW } = constants
1919

20+
export const CMD_NAME = 'unset'
21+
2022
const description = 'Clear the value of a local CLI config item'
2123

2224
const hidden = false
@@ -33,7 +35,7 @@ async function run(
3335
{ parentName }: { parentName: string },
3436
): Promise<void> {
3537
const config: CliCommandConfig = {
36-
commandName: 'unset',
38+
commandName: CMD_NAME,
3739
description,
3840
hidden,
3941
flags: {

src/commands/fix/cmd-fix.mts

Lines changed: 105 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { checkCommandInput } from '../../utils/check-input.mts'
1313
import { cmdFlagValueToArray } from '../../utils/cmd.mts'
1414
import { getOutputKind } from '../../utils/get-output-kind.mts'
1515
import { meowOrExit } from '../../utils/meow-with-subcommands.mts'
16-
import { getFlagListOutput } from '../../utils/output-formatting.mts'
16+
import {
17+
getFlagApiRequirementsOutput,
18+
getFlagListOutput,
19+
} from '../../utils/output-formatting.mts'
1720
import { RangeStyles } from '../../utils/semver.mts'
1821
import { getDefaultOrgSlug } from '../ci/fetch-default-org-slug.mts'
1922

@@ -22,74 +25,92 @@ import type { RangeStyle } from '../../utils/semver.mts'
2225

2326
const { DRY_RUN_NOT_SAVING } = constants
2427

28+
export const CMD_NAME = 'fix'
29+
2530
const DEFAULT_LIMIT = 10
2631

27-
const config: CliCommandConfig = {
28-
commandName: 'fix',
29-
description: 'Update dependencies with "fixable" Socket alerts',
30-
hidden: false,
31-
flags: {
32-
...commonFlags,
33-
autoMerge: {
34-
type: 'boolean',
35-
default: false,
36-
description: `Enable auto-merge for pull requests that Socket opens.\nSee ${terminalLink(
37-
'GitHub documentation',
38-
'https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-auto-merge-for-pull-requests-in-your-repository',
39-
)} for managing auto-merge for pull requests in your repository.`,
40-
},
41-
autopilot: {
42-
type: 'boolean',
43-
default: false,
44-
description: `Shorthand for --autoMerge --test`,
45-
},
46-
ghsa: {
47-
type: 'string',
48-
default: [],
49-
description: `Provide a list of ${terminalLink(
50-
'GHSA IDs',
51-
'https://docs.github.com/en/code-security/security-advisories/working-with-global-security-advisories-from-the-github-advisory-database/about-the-github-advisory-database#about-ghsa-ids',
52-
)} to compute fixes for, as either a comma separated value or as multiple flags.\nUse '--ghsa all' to lookup all GHSA IDs and compute fixes for them.`,
53-
isMultiple: true,
54-
hidden: true,
55-
},
56-
limit: {
57-
type: 'number',
58-
default: DEFAULT_LIMIT,
59-
description: `The number of fixes to attempt at a time (default ${DEFAULT_LIMIT})`,
60-
},
61-
maxSatisfying: {
62-
type: 'boolean',
63-
default: true,
64-
description: 'Use the maximum satisfying version for dependency updates',
65-
hidden: true,
66-
},
67-
minSatisfying: {
68-
type: 'boolean',
69-
default: false,
70-
description:
71-
'Constrain dependency updates to the minimum satisfying version',
72-
},
73-
prCheck: {
74-
type: 'boolean',
75-
default: true,
76-
description: 'Check for an existing PR before attempting a fix',
77-
hidden: true,
78-
},
79-
purl: {
80-
type: 'string',
81-
default: [],
82-
description: `Provide a list of ${terminalLink(
83-
'PURLs',
84-
'https://github.com/package-url/purl-spec?tab=readme-ov-file#purl',
85-
)} to compute fixes for, as either a comma separated value or as\nmultiple flags, instead of querying the Socket API`,
86-
isMultiple: true,
87-
shortFlag: 'p',
88-
},
89-
rangeStyle: {
90-
type: 'string',
91-
default: 'preserve',
92-
description: `
32+
const description = 'Update dependencies with "fixable" Socket alerts'
33+
34+
const hidden = false
35+
36+
export const cmdFix = {
37+
description,
38+
hidden,
39+
run,
40+
}
41+
42+
async function run(
43+
argv: string[] | readonly string[],
44+
importMeta: ImportMeta,
45+
{ parentName }: { parentName: string },
46+
): Promise<void> {
47+
const config: CliCommandConfig = {
48+
commandName: CMD_NAME,
49+
description,
50+
hidden,
51+
flags: {
52+
...commonFlags,
53+
autoMerge: {
54+
type: 'boolean',
55+
default: false,
56+
description: `Enable auto-merge for pull requests that Socket opens.\nSee ${terminalLink(
57+
'GitHub documentation',
58+
'https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-auto-merge-for-pull-requests-in-your-repository',
59+
)} for managing auto-merge for pull requests in your repository.`,
60+
},
61+
autopilot: {
62+
type: 'boolean',
63+
default: false,
64+
description: `Shorthand for --autoMerge --test`,
65+
},
66+
ghsa: {
67+
type: 'string',
68+
default: [],
69+
description: `Provide a list of ${terminalLink(
70+
'GHSA IDs',
71+
'https://docs.github.com/en/code-security/security-advisories/working-with-global-security-advisories-from-the-github-advisory-database/about-the-github-advisory-database#about-ghsa-ids',
72+
)} to compute fixes for, as either a comma separated value or as multiple flags.\nUse '--ghsa all' to lookup all GHSA IDs and compute fixes for them.`,
73+
isMultiple: true,
74+
hidden: true,
75+
},
76+
limit: {
77+
type: 'number',
78+
default: DEFAULT_LIMIT,
79+
description: `The number of fixes to attempt at a time (default ${DEFAULT_LIMIT})`,
80+
},
81+
maxSatisfying: {
82+
type: 'boolean',
83+
default: true,
84+
description:
85+
'Use the maximum satisfying version for dependency updates',
86+
hidden: true,
87+
},
88+
minSatisfying: {
89+
type: 'boolean',
90+
default: false,
91+
description:
92+
'Constrain dependency updates to the minimum satisfying version',
93+
},
94+
prCheck: {
95+
type: 'boolean',
96+
default: true,
97+
description: 'Check for an existing PR before attempting a fix',
98+
hidden: true,
99+
},
100+
purl: {
101+
type: 'string',
102+
default: [],
103+
description: `Provide a list of ${terminalLink(
104+
'PURLs',
105+
'https://github.com/package-url/purl-spec?tab=readme-ov-file#purl',
106+
)} to compute fixes for, as either a comma separated value or as\nmultiple flags, instead of querying the Socket API`,
107+
isMultiple: true,
108+
shortFlag: 'p',
109+
},
110+
rangeStyle: {
111+
type: 'string',
112+
default: 'preserve',
113+
description: `
93114
Define how dependency version ranges are updated in package.json (default 'preserve').
94115
Available styles:
95116
* caret - Use ^ range for compatible updates (e.g. ^1.2.3)
@@ -101,42 +122,34 @@ Available styles:
101122
* preserve - Retain the existing version range style as-is
102123
* tilde - Use ~ range for patch/minor updates (e.g. ~1.2.3)
103124
`.trim(),
125+
},
126+
test: {
127+
type: 'boolean',
128+
default: false,
129+
description: 'Verify the fix by running unit tests',
130+
},
131+
testScript: {
132+
type: 'string',
133+
default: 'test',
134+
description: "The test script to run for fix attempts (default 'test')",
135+
},
104136
},
105-
test: {
106-
type: 'boolean',
107-
default: false,
108-
description: 'Verify the fix by running unit tests',
109-
},
110-
testScript: {
111-
type: 'string',
112-
default: 'test',
113-
description: "The test script to run for fix attempts (default 'test')",
114-
},
115-
},
116-
help: (command, config) => `
137+
help: (command, config) => `
117138
Usage
118139
$ ${command} [options] [CWD=.]
119140
141+
API Token Requirements
142+
${getFlagApiRequirementsOutput(`${parentName}:${CMD_NAME}`)}
143+
120144
Options
121145
${getFlagListOutput(config.flags)}
122146
123147
Examples
124148
$ ${command}
125149
$ ${command} ./proj/tree --autoMerge
126-
`,
127-
}
128-
129-
export const cmdFix = {
130-
description: config.description,
131-
hidden: config.hidden,
132-
run,
133-
}
150+
`,
151+
}
134152

135-
async function run(
136-
argv: string[] | readonly string[],
137-
importMeta: ImportMeta,
138-
{ parentName }: { parentName: string },
139-
): Promise<void> {
140153
const cli = meowOrExit({
141154
allowUnknownFlags: false,
142155
argv,

src/commands/fix/cmd-fix.test.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ describe('socket fix', async () => {
1919
Usage
2020
$ socket fix [options] [CWD=.]
2121
22+
API Token Requirements
23+
- Quota: 100 units
24+
- Permissions: packages:list
25+
2226
Options
2327
--auto-merge Enable auto-merge for pull requests that Socket opens.
2428
See GitHub documentation (\\u200bhttps://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-auto-merge-for-pull-requests-in-your-repository\\u200b) for managing auto-merge for pull requests in your repository.

src/commands/login/cmd-login.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function run(
3333
{ parentName }: { parentName: string },
3434
): Promise<void> {
3535
const config: CliCommandConfig = {
36-
commandName: 'login',
36+
commandName: CMD_NAME,
3737
description,
3838
hidden,
3939
flags: {

0 commit comments

Comments
 (0)