mirror of https://github.com/aminya/setup-cpp
feat: add --help for the cli
This commit is contained in:
parent
c654c9880c
commit
d028e18862
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
43
src/main.ts
43
src/main.ts
|
@ -67,11 +67,18 @@ 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> {
|
||||||
// parse options using mri or github actions
|
// parse options using mri or github actions
|
||||||
const opts = mri<Record<Inputs, string | undefined>>(args, {
|
const opts = mri<Record<Inputs, string | undefined> & { help: boolean }>(args, {
|
||||||
string: inputs,
|
string: inputs,
|
||||||
default: Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)])),
|
default: Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)])),
|
||||||
|
alias: { h: "help" },
|
||||||
|
boolean: "help",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// print help
|
||||||
|
if (opts.help) {
|
||||||
|
printHelp()
|
||||||
|
}
|
||||||
|
|
||||||
// cpu architecture
|
// cpu architecture
|
||||||
const arch = opts.architecture ?? process.arch
|
const arch = opts.architecture ?? process.arch
|
||||||
|
|
||||||
|
@ -164,11 +171,10 @@ export async function main(args: string[]): Promise<number> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// report the messages in the end
|
// report the messages in the end
|
||||||
console.log("\n\n\n")
|
|
||||||
successMessages.forEach((tool) => core.info(tool))
|
successMessages.forEach((tool) => core.info(tool))
|
||||||
errorMessages.forEach((tool) => core.error(tool))
|
errorMessages.forEach((tool) => core.error(tool))
|
||||||
|
|
||||||
core.info("install-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
|
||||||
}
|
}
|
||||||
// Run main
|
// Run main
|
||||||
|
@ -182,6 +188,37 @@ main(process.argv)
|
||||||
process.exitCode = 1
|
process.exitCode = 1
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function printHelp() {
|
||||||
|
core.info(`
|
||||||
|
setup-cpp [options]
|
||||||
|
setup-cpp --compiler llvm --cmake true --ninja true --ccache true --conan "1.40.1"
|
||||||
|
|
||||||
|
Install all the tools required for building and testing C++/C projects.
|
||||||
|
|
||||||
|
--architecture\t the cpu architecture to install the tools for. By default it uses the current CPU architecture.
|
||||||
|
--compiler\t the <compiler> to install.
|
||||||
|
\t You can specify the version instead of specifying just the name e.g: --compiler 'llvm-11'
|
||||||
|
|
||||||
|
--tool_name\t pass "true" or pass the <version> you would like to install for this tool.
|
||||||
|
|
||||||
|
All the available tools:
|
||||||
|
--llvm
|
||||||
|
--gcc
|
||||||
|
--cmake
|
||||||
|
--ninja
|
||||||
|
--meson
|
||||||
|
--conan
|
||||||
|
--ccache
|
||||||
|
--cppcheck
|
||||||
|
--doxygen
|
||||||
|
--gcovr
|
||||||
|
--opencppcoverage
|
||||||
|
--python
|
||||||
|
--choco
|
||||||
|
--brew
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
/** Get an object from github actions */
|
/** Get an object from github actions */
|
||||||
function maybeGetInput(key: string) {
|
function maybeGetInput(key: string) {
|
||||||
const value = core.getInput(key.toLowerCase())
|
const value = core.getInput(key.toLowerCase())
|
||||||
|
|
Loading…
Reference in New Issue