feat(cli): add help message and usage documentation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "issue-scheduler",
|
||||
"description": "Schedule issues in Gitea or Github from issue templates",
|
||||
"description": "Schedule issues in Gitea or GitHub using issue templates",
|
||||
"version": "0.0.0",
|
||||
"main": "dist/index.js",
|
||||
|
||||
|
||||
27
src/cli.ts
27
src/cli.ts
@@ -8,6 +8,10 @@ export interface CLIConfig {
|
||||
// doesn't log to stdout/stderr (still logs to file if --log-file)
|
||||
quiet: boolean
|
||||
}
|
||||
// TODO: Git client shouldn't be identified from the config,
|
||||
// but from the host url or a custom config property
|
||||
// TODO: add --list-issue-templates <user> <repo> <token> : list results from api.getIssueTemplates
|
||||
// TODO: add other utility commands
|
||||
|
||||
export const defaults: CLIConfig = {
|
||||
config_filepath: "config.toml",
|
||||
@@ -97,14 +101,37 @@ export function optionalBooleanFlag(args: string[], flags: string[]): boolean {
|
||||
return value === null;
|
||||
}
|
||||
|
||||
const Usage = (program_name: string) => `\
|
||||
Usage: ${program_name} [options...]
|
||||
|
||||
Issue Scheduler - Schedule issues in Gitea or GitHub using issue templates
|
||||
|
||||
Options:
|
||||
-h, --help Display this message
|
||||
-c, --config <filepath> Config file [default: "config.toml"]
|
||||
-l, --log-file <filepath> Logs output to file
|
||||
-v, --verbose Verbose logging
|
||||
-q, --quiet Only logs to --log-file (if provided)
|
||||
`
|
||||
|
||||
/**
|
||||
* Parse command line arguments from a string array (process.argv)
|
||||
* @param args Command line arguments
|
||||
* @return {CLIConfig} Parsed flags
|
||||
*/
|
||||
export function parseArgs(args: string[]): CLIConfig {
|
||||
if (args.length < 2) { // [node executable, program path, ...]
|
||||
// TODO: log error
|
||||
process.exit(1)
|
||||
}
|
||||
const config = defaults
|
||||
|
||||
const helpValue = optionalBooleanFlag(args, ["--help", "-h"])
|
||||
if (helpValue) {
|
||||
console.log(Usage(args[1]!))
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const configValue = optionalStringFlag(args, ["--config", "-c"])
|
||||
if (configValue) config.config_filepath = configValue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user