Skip to content

Commit

Permalink
add version and help CLI flags
Browse files Browse the repository at this point in the history
  • Loading branch information
bcheidemann committed Aug 13, 2023
1 parent 0b37791 commit 7bc7ab1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/cli/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export function parseLangArgs(context: ParseLangArgsContext): Config {
case "--lang":
case "-l":
return parseLangArg(context);
case "--help":
case "-h":
return parseHelpArg(context);
case "--version":
case "-v":
return parseVersionArg(context);
default:
return parseFileArg(context, arg);
}
Expand Down Expand Up @@ -57,6 +63,23 @@ export function parseLangArg(
}
}

export function parseHelpArg(
_context: ParseLangArgsContext,
): Config {
return {
help: true,
invalidArgs: false,
};
}

export function parseVersionArg(
_context: ParseLangArgsContext,
): Config {
return {
version: true,
};
}

export function parseFileArg(
context: ParseLangArgsContext,
arg: string,
Expand Down
5 changes: 5 additions & 0 deletions lib/cli/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ export type HelpConfig = {
message?: string;
};

export type VersionConfig = {
version: true;
};

export type LangConfig = {
lang: Lang;
files: string[];
};

export type Config =
| HelpConfig
| VersionConfig
| LangConfig;
5 changes: 5 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ async function main(args: string[]): Promise<0 | 1> {
return 0;
}

if ("version" in config) {
console.log("1.0.1");
return 0;
}

if ("lang" in config) {
let exitStatusCode: 0 | 1 = 0;

Expand Down

0 comments on commit 7bc7ab1

Please sign in to comment.