-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14be413
commit f209f8f
Showing
2 changed files
with
47 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2021, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { cli } from 'cli-ux'; | ||
|
||
/** | ||
* This class is a light wrapper around cli.action that allows us to | ||
* automatically suppress any actions if `--json` flag is present. | ||
*/ | ||
export class Spinner { | ||
public constructor(private jsonEnabled: boolean) {} | ||
|
||
/** | ||
* Start a spinner on the console. | ||
*/ | ||
public start(action: string, status?: string, opts?: { stdout?: boolean }): void { | ||
if (!this.jsonEnabled) cli.action.start(action, status, opts); | ||
} | ||
|
||
/** | ||
* Stop a spinner on the console. | ||
*/ | ||
public stop(msg?: string): void { | ||
if (!this.jsonEnabled) cli.action.stop(msg); | ||
} | ||
|
||
/** | ||
* Pause a spinner on the console. | ||
*/ | ||
public pause(fn: () => unknown, icon?: string): void { | ||
if (!this.jsonEnabled) cli.action.pause(fn, icon); | ||
} | ||
} |