pdf-tools/cli/argParser.ts

34 lines
623 B
TypeScript

export class ArgParser {
private args: string[];
constructor(args: string[]) {
this.args = args;
}
public get(key: string) {
const index = this.args.indexOf(key);
if (index === -1) return null;
return this.args[index + 1];
}
get flags() {
return this.args.filter((arg) => arg.startsWith("-"));
}
get nonFlags() {
return this.args.filter((arg) => !arg.startsWith("-"));
}
get namedArgs() {
return this.args.filter((arg) => arg.startsWith("--"));
}
get task() {
return this.nonFlags[0];
}
static parse(args: string[]) {
return new ArgParser(args);
}
}