feat: add --help for the cli

This commit is contained in:
Amin Yahyaabadi 2021-09-17 13:09:00 -05:00
parent c654c9880c
commit d028e18862
3 changed files with 42 additions and 5 deletions

2
dist/main.js vendored

File diff suppressed because one or more lines are too long

2
dist/main.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -67,11 +67,18 @@ const inputs: Array<Inputs> = ["compiler", "architecture", ...tools]
/** The main entry function */
export async function main(args: string[]): Promise<number> {
// 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,
default: Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)])),
alias: { h: "help" },
boolean: "help",
})
// print help
if (opts.help) {
printHelp()
}
// cpu architecture
const arch = opts.architecture ?? process.arch
@ -164,11 +171,10 @@ export async function main(args: string[]): Promise<number> {
}
// report the messages in the end
console.log("\n\n\n")
successMessages.forEach((tool) => core.info(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
}
// Run main
@ -182,6 +188,37 @@ main(process.argv)
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 */
function maybeGetInput(key: string) {
const value = core.getInput(key.toLowerCase())