-
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.
Merge pull request #21 from salesforcecli/mdonnalley/spinner
feat: add spinner methods
- Loading branch information
Showing
2 changed files
with
61 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,51 @@ | ||
/* | ||
* 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 the spinner on the console. | ||
*/ | ||
public stop(msg?: string): void { | ||
if (!this.jsonEnabled) cli.action.stop(msg); | ||
} | ||
|
||
/** | ||
* Set the status of the current spinner. | ||
*/ | ||
public set status(status: string | undefined) { | ||
if (!this.jsonEnabled) cli.action.status = status; | ||
} | ||
|
||
/** | ||
* Get the status of the current spinner. | ||
*/ | ||
public get status(): string | undefined { | ||
return cli.action.status; | ||
} | ||
|
||
/** | ||
* Pause the spinner on the console. | ||
*/ | ||
public pause(fn: () => unknown, icon?: string): void { | ||
if (!this.jsonEnabled) cli.action.pause(fn, icon); | ||
} | ||
} |