Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ng-dev): create system for registering functions to be called on…
… command completion Create a callback system to call functions after a command completes.
- Loading branch information
1 parent
5c9772c
commit 1e09df3
Showing
5 changed files
with
66 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import yargs, {Arguments, Argv} from 'yargs'; | ||
|
||
// A function to be called when the command completes. | ||
type CompletedFn = (err: Error | null) => Promise<void> | void; | ||
|
||
/** List of functions to be called upon command completion. */ | ||
const completedFunctions: CompletedFn[] = []; | ||
|
||
/** Register a function to be called when the command completes. */ | ||
export function registerCompletedFunction(fn: CompletedFn) { | ||
completedFunctions.push(fn); | ||
} | ||
|
||
/** | ||
* Run the yargs process, as configured by the supplied function, calling a set of completion | ||
* functions after the command completes. | ||
*/ | ||
export function runParserWithCompletedFunctions(applyConfiguration: (argv: Argv) => Argv) { | ||
applyConfiguration(yargs([])).parse(process.argv.slice(2), async (err: Error | null) => { | ||
for (const completedFunc of completedFunctions) { | ||
await completedFunc(err); | ||
} | ||
}); | ||
} |