From 69a300f69dde47594b09a8d5e0edf9a703979154 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Sun, 28 Nov 2021 22:27:26 -0800 Subject: [PATCH] util: cli: Add function wrapper with spinner --- src/util/cli.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/util/cli.ts b/src/util/cli.ts index f8918b0..2208613 100644 --- a/src/util/cli.ts +++ b/src/util/cli.ts @@ -17,3 +17,14 @@ export function startActionSpinner(action: string) { export function stopActionSpinner(spinner: ora.Ora) { spinner.stopAndPersist() } + +export async function withSpinner( + action: string, + callback: (spinner: ora.Ora) => Promise, +) { + let spinner = createActionSpinner(action) + let ret = await callback(spinner) + stopActionSpinner(spinner) + + return ret +}