Skip to content

Commit 43d46ef

Browse files
committed
fix: make setup-cpp --version/help immutable
1 parent 3ce1db2 commit 43d46ef

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

dist/legacy/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli-options.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import type { InstallationInfo } from "./utils/setup/setupBin.js"
77

88
export function parseArgs(args: string[]): Opts {
99
const defaults = Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)]))
10-
defaults["setup-cpp"] = "true"
11-
1210
return mri<Record<Inputs, string | undefined> & { help: boolean; version: boolean; "setup-cpp": boolean }>(args, {
1311
string: [...inputs, "timeout", "node-package-manager"],
1412
default: defaults,
@@ -70,7 +68,7 @@ export type Opts = mri.Argv<
7068
Record<Inputs, string | undefined> & {
7169
help: boolean
7270
version: boolean
73-
"setup-cpp": boolean
71+
"setup-cpp"?: boolean
7472
timeout?: string
7573
"node-package-manager"?: string
7674
}

src/setup-cpp.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ async function main(args: string[]): Promise<number> {
2828
// parse options using mri or github actions
2929
const opts = parseArgs(args)
3030

31-
const installSetupCppPromise = opts["setup-cpp"]
32-
? installSetupCpp(packageJson.version, opts["node-package-manager"])
33-
: Promise.resolve()
34-
3531
// print help
3632
if (opts.help) {
3733
printHelp()
@@ -129,13 +125,20 @@ async function main(args: string[]): Promise<number> {
129125

130126
await finalizeRC(rcOptions)
131127

132-
if (successMessages.length === 0 && errorMessages.length === 0) {
133-
if (!opts.version && !opts.help) {
134-
info("setup-cpp was called without any arguments. Nothing to do.")
135-
}
136-
return 0
128+
const noTool = successMessages.length === 0 && errorMessages.length === 0
129+
130+
// if setup-cpp option is not passed, install setup-cpp by default unless only help or version is passed
131+
// So that --help and --version are immutable
132+
if (opts["setup-cpp"] === undefined) {
133+
opts["setup-cpp"] = !(noTool && (opts.version || opts.help))
137134
}
138135

136+
const installSetupCppPromise = opts["setup-cpp"]
137+
? installSetupCpp(packageJson.version, opts["node-package-manager"])
138+
: Promise.resolve()
139+
140+
await Promise.all([checkUpdatePromise, installSetupCppPromise])
141+
139142
// report the messages in the end
140143
for (const tool of successMessages) {
141144
success(tool)
@@ -144,27 +147,26 @@ async function main(args: string[]): Promise<number> {
144147
error(tool)
145148
}
146149

147-
info("setup-cpp finished")
148-
149-
if (!GITHUB_ACTIONS) {
150-
switch (process.platform) {
151-
case "win32": {
152-
warning("Run `RefreshEnv.cmd` or restart your shell to update the environment.")
153-
break
154-
}
155-
case "linux":
156-
case "darwin": {
157-
warning("Run `source ~/.cpprc` or restart your shell to update the environment.")
158-
break
159-
}
160-
default: {
161-
// nothing
150+
if (successMessages.length !== 0 || errorMessages.length !== 0) {
151+
info("setup-cpp finished")
152+
153+
if (!GITHUB_ACTIONS) {
154+
switch (process.platform) {
155+
case "win32": {
156+
warning("Run `RefreshEnv.cmd` or restart your shell to update the environment.")
157+
break
158+
}
159+
case "linux":
160+
case "darwin": {
161+
warning("Run `source ~/.cpprc` or restart your shell to update the environment.")
162+
break
163+
}
164+
default: {
165+
// nothing
166+
}
162167
}
163168
}
164169
}
165-
166-
await Promise.all([checkUpdatePromise, installSetupCppPromise])
167-
168170
return errorMessages.length === 0 ? 0 : 1 // exit with non-zero if any error message
169171
}
170172

0 commit comments

Comments
 (0)