Skip to content

Commit

Permalink
added documentation for ARGS
Browse files Browse the repository at this point in the history
  • Loading branch information
duart38 committed Mar 15, 2021
1 parent 9012c5b commit 654f65b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions builder/ARGS.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Deno command line argument specific code builder.
* @example ARGS.on("-x")
* .do(()=>console.log("-x"))
* .else(()=>console.log("-x not found"));
*/
export class ARGS {
private args: string[];
private includesAll: boolean;
Expand All @@ -6,20 +12,52 @@ export class ARGS {
this.includesAll = this.args.every((arg)=>Deno.args.includes(arg));
}

/**
* runs a function when all arguments provided are set
* @example ARGS.on("-x")
* .do(()=>console.log("-x"))
* .else(()=>console.log("-x not found"));
* @param run function to run
* @returns this
*/
public do(run: ()=>void): this {
if(this.includesAll) run();
return this;
}

/**
* runs a function when one or more arguments provided are NOT set
* @example ARGS.on("-x")
* .do(()=>console.log("-x"))
* .else(()=>console.log("-x not found"));
* @param run function to run
* @returns this
*/
public else(run: ()=>void): this {
if(!this.includesAll) run();
return this;
}

/**
* Helper method to facilitate declarative chaining
* @example ARGS.on("-x")
* .do(()=>console.log("-x code"))
* .on("-a")
* .do(()=>console.log("-a code"));
* @param name
* @returns new instance of ARGS
*/
public on(...argument: string[]): ARGS {
return new ARGS(argument);
}

/**
* Helper method to start chaining
* @example ARGS.on("-x")
* .do(()=>console.log("-x code"))
* @param name
* @returns new instance of ARGS
*/
static on(...argument: string[]): ARGS{
return new ARGS(argument);
}
Expand Down

0 comments on commit 654f65b

Please sign in to comment.