mirror of https://github.com/aminya/setup-cpp
fix: add colors to cli
This commit is contained in:
parent
d82045ec40
commit
1a1befa1c9
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
12
src/main.ts
12
src/main.ts
|
@ -67,6 +67,8 @@ const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
|
||||||
|
|
||||||
/** The main entry function */
|
/** The main entry function */
|
||||||
export async function main(args: string[]): Promise<number> {
|
export async function main(args: string[]): Promise<number> {
|
||||||
|
const isCI = Boolean(process.env.CI)
|
||||||
|
|
||||||
// parse options using mri or github actions
|
// parse options using mri or github actions
|
||||||
const opts = mri<Record<Inputs, string | undefined> & { help: boolean }>(args, {
|
const opts = mri<Record<Inputs, string | undefined> & { help: boolean }>(args, {
|
||||||
string: inputs,
|
string: inputs,
|
||||||
|
@ -162,18 +164,18 @@ export async function main(args: string[]): Promise<number> {
|
||||||
if (installationInfo !== undefined) {
|
if (installationInfo !== undefined) {
|
||||||
successMessages.push(getSuccessMessage(tool, installationInfo))
|
successMessages.push(getSuccessMessage(tool, installationInfo))
|
||||||
} else {
|
} else {
|
||||||
successMessages.push(` ${tool} was successfully installed`)
|
successMessages.push(`${tool} was successfully installed`)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// push error message to the logger
|
// push error message to the logger
|
||||||
errorMessages.push(` ${tool} failed to install`)
|
errorMessages.push(`${tool} failed to install`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// report the messages in the end
|
// report the messages in the end
|
||||||
successMessages.forEach((tool) => core.info(tool))
|
successMessages.forEach((tool) => (isCI ? core.info(tool) : console.log(`\x1b[32m${tool}\x1b[0m`)))
|
||||||
errorMessages.forEach((tool) => core.error(tool))
|
errorMessages.forEach((tool) => (isCI ? core.error(tool) : console.log(`\x1b[31m${tool}\x1b[0m`)))
|
||||||
|
|
||||||
core.info("setup_cpp finished")
|
core.info("setup_cpp finished")
|
||||||
return errorMessages.length === 0 ? 0 : 1 // exit with non-zero if any error message
|
return errorMessages.length === 0 ? 0 : 1 // exit with non-zero if any error message
|
||||||
|
@ -230,7 +232,7 @@ function maybeGetInput(key: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSuccessMessage(tool: string, installationInfo: InstallationInfo) {
|
function getSuccessMessage(tool: string, installationInfo: InstallationInfo) {
|
||||||
let success = ` ${tool} was successfully installed`
|
let success = `${tool} was successfully installed`
|
||||||
if ("installDir" in installationInfo) {
|
if ("installDir" in installationInfo) {
|
||||||
success += `\nThe installation direcotry is ${installationInfo.installDir}`
|
success += `\nThe installation direcotry is ${installationInfo.installDir}`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue