Skip to content

Commit 1a1befa

Browse files
committed
fix: add colors to cli
1 parent d82045e commit 1a1befa

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

dist/setup_cpp.js

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

dist/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.

src/main.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
6767

6868
/** The main entry function */
6969
export async function main(args: string[]): Promise<number> {
70+
const isCI = Boolean(process.env.CI)
71+
7072
// parse options using mri or github actions
7173
const opts = mri<Record<Inputs, string | undefined> & { help: boolean }>(args, {
7274
string: inputs,
@@ -162,18 +164,18 @@ export async function main(args: string[]): Promise<number> {
162164
if (installationInfo !== undefined) {
163165
successMessages.push(getSuccessMessage(tool, installationInfo))
164166
} else {
165-
successMessages.push(` ${tool} was successfully installed`)
167+
successMessages.push(`${tool} was successfully installed`)
166168
}
167169
} catch (e) {
168170
// push error message to the logger
169-
errorMessages.push(` ${tool} failed to install`)
171+
errorMessages.push(`${tool} failed to install`)
170172
}
171173
}
172174
}
173175

174176
// report the messages in the end
175-
successMessages.forEach((tool) => core.info(tool))
176-
errorMessages.forEach((tool) => core.error(tool))
177+
successMessages.forEach((tool) => (isCI ? core.info(tool) : console.log(`\x1b[32m${tool}\x1b[0m`)))
178+
errorMessages.forEach((tool) => (isCI ? core.error(tool) : console.log(`\x1b[31m${tool}\x1b[0m`)))
177179

178180
core.info("setup_cpp finished")
179181
return errorMessages.length === 0 ? 0 : 1 // exit with non-zero if any error message
@@ -230,7 +232,7 @@ function maybeGetInput(key: string) {
230232
}
231233

232234
function getSuccessMessage(tool: string, installationInfo: InstallationInfo) {
233-
let success = ` ${tool} was successfully installed`
235+
let success = `${tool} was successfully installed`
234236
if ("installDir" in installationInfo) {
235237
success += `\nThe installation direcotry is ${installationInfo.installDir}`
236238
}

0 commit comments

Comments
 (0)