initial cli api, some movement on tool selection
This commit is contained in:
33
cli/argParser.ts
Normal file
33
cli/argParser.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user