util: cli: Add function wrapper with spinner
This commit is contained in:
parent
f4dee594a7
commit
69a300f69d
1 changed files with 11 additions and 0 deletions
|
@ -17,3 +17,14 @@ export function startActionSpinner(action: string) {
|
||||||
export function stopActionSpinner(spinner: ora.Ora) {
|
export function stopActionSpinner(spinner: ora.Ora) {
|
||||||
spinner.stopAndPersist()
|
spinner.stopAndPersist()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function withSpinner<Return>(
|
||||||
|
action: string,
|
||||||
|
callback: (spinner: ora.Ora) => Promise<Return>,
|
||||||
|
) {
|
||||||
|
let spinner = createActionSpinner(action)
|
||||||
|
let ret = await callback(spinner)
|
||||||
|
stopActionSpinner(spinner)
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue