diff --git a/package.json b/package.json index 63fd56c..e42bf48 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cli.ts b/src/cli.ts index 9375946..6afcf7d 100644 --- a/src/cli.ts +++ b/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 : 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 Config file [default: "config.toml"] + -l, --log-file 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