util: cli: Add function wrapper with spinner

This commit is contained in:
Danny Lin 2021-11-28 22:27:26 -08:00
parent f4dee594a7
commit 69a300f69d

View file

@ -17,3 +17,14 @@ export function startActionSpinner(action: string) {
export function stopActionSpinner(spinner: ora.Ora) {
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
}