-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db pull): add spinner in CLI when introspecting (#12897)
Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
527 additions
and
145 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,59 @@ | ||
import type { Options as OraOptions } from 'ora' | ||
import ora from 'ora' | ||
|
||
const defaultOraOptions: OraOptions = { | ||
spinner: 'dots', | ||
color: 'cyan', | ||
indent: 0, | ||
stream: process.stdout, | ||
} | ||
|
||
/** | ||
* Methods available to a spinner instance that has already started. | ||
*/ | ||
export interface SpinnerStarted { | ||
success(text?: string): void | ||
failure(text?: string): void | ||
} | ||
|
||
/** | ||
* Closure that starts a spinner if `enableOutput` is true, and returns a `SpinnerStarted` instance. | ||
* Note: the spinner will only be enabled if the stream is being run inside a TTY context (not spawned or piped) and/or not in a CI environment. | ||
* @param enableOutput Whether to enable or disable any output. Useful e.g. for "--print" flags in commands. | ||
* @param oraOptions Additional options to pass to `ora` for customizing the spinner. | ||
* @returns | ||
*/ | ||
export function createSpinner(enableOutput = true, oraOptions: Partial<OraOptions> = {}) { | ||
const actualOptions = { ...defaultOraOptions, ...oraOptions } | ||
|
||
return (text: string): SpinnerStarted => { | ||
if (!enableOutput) { | ||
return { | ||
success: () => {}, | ||
failure: () => {}, | ||
} | ||
} | ||
|
||
actualOptions.stream?.write('\n') | ||
const spinner = ora(actualOptions) | ||
spinner.start(text) | ||
|
||
return { | ||
/** | ||
* Stop the spinner, change it to a green ✔ and persist the current text, or text if provided. | ||
* @param textSuccess Will persist text if provided. | ||
*/ | ||
success: (textSuccess) => { | ||
spinner.succeed(textSuccess) | ||
}, | ||
|
||
/** | ||
* Stop the spinner, change it to a red ✖ and persist the current text, or text if provided. | ||
* @param textFailure Will persist text if provided. | ||
*/ | ||
failure: (textFailure) => { | ||
spinner.fail(textFailure) | ||
}, | ||
} | ||
} | ||
} |
Oops, something went wrong.