Skip to content

Commit e86df99

Browse files
committed
Normalize options passed to handleFix
1 parent 85467da commit e86df99

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

src/commands/fix/cmd-fix.mts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,23 @@ async function run(
111111
parentName,
112112
})
113113

114-
const { autopilot, json, markdown } = cli.flags
115-
let { autoMerge, rangeStyle, test } = cli.flags
114+
const { autopilot, json, markdown } = cli.flags as {
115+
autopilot: boolean
116+
json: boolean
117+
markdown: boolean
118+
}
116119
const outputKind = getOutputKind(json, markdown)
117-
let [cwd = '.'] = cli.input
118-
// Note: path.resolve vs .join:
119-
// If given path is absolute then cwd should not affect it.
120-
cwd = path.resolve(process.cwd(), cwd)
121120

122-
if (autopilot) {
123-
autoMerge = true
124-
test = true
121+
let rangeStyle = cli.flags['rangeStyle'] as RangeStyle
122+
if (!rangeStyle) {
123+
rangeStyle = 'preserve'
125124
}
126125

127126
const wasValidInput = checkCommandInput(outputKind, {
128-
test: RangeStyles.includes(cli.flags['rangeStyle'] as string),
127+
test: RangeStyles.includes(rangeStyle),
129128
message: `Expecting range style of ${joinOr(RangeStyles)}`,
130129
pass: 'ok',
131-
fail: 'missing',
130+
fail: 'invalid',
132131
})
133132
if (!wasValidInput) {
134133
return
@@ -139,30 +138,37 @@ async function run(
139138
return
140139
}
141140

142-
let purls: string[] = Array.isArray(cli.flags['purl'])
143-
? cli.flags['purl']
144-
: []
145-
purls = purls.flatMap(p => p.split(/, */))
141+
let [cwd = '.'] = cli.input
142+
// Note: path.resolve vs .join:
143+
// If given path is absolute then cwd should not affect it.
144+
cwd = path.resolve(process.cwd(), cwd)
146145

147-
if (
148-
!['caret', 'gt', 'gte', 'lt', 'lte', 'pin', 'preserve', 'tilde'].includes(
149-
rangeStyle as string,
150-
)
151-
) {
152-
rangeStyle = 'preserve'
146+
let autoMerge = Boolean(cli.flags['autoMerge'])
147+
let test = Boolean(cli.flags['test'])
148+
if (autopilot) {
149+
autoMerge = true
150+
test = true
153151
}
154152

153+
const limit =
154+
(cli.flags['limit']
155+
? parseInt(String(cli.flags['limit'] || ''), 10)
156+
: Infinity) || Infinity
157+
158+
const purls: string[] = Array.isArray(cli.flags['purl'])
159+
? cli.flags['purl'].flatMap(p => p.split(/, */))
160+
: []
161+
162+
const testScript = String(cli.flags['testScript'] || 'test')
163+
155164
await handleFix({
156-
autoMerge: Boolean(autoMerge),
165+
autoMerge,
157166
cwd,
158-
limit:
159-
(cli.flags['limit']
160-
? parseInt(String(cli.flags['limit'] || ''), 10)
161-
: Infinity) || Infinity,
167+
limit,
162168
outputKind,
163169
purls,
164-
rangeStyle: rangeStyle as RangeStyle,
165-
test: Boolean(test),
166-
testScript: String(cli.flags['testScript'] || 'test'),
170+
rangeStyle,
171+
test,
172+
testScript,
167173
})
168174
}

0 commit comments

Comments
 (0)