-
Notifications
You must be signed in to change notification settings - Fork 11
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
7a11772
commit f4a03ca
Showing
7 changed files
with
172 additions
and
15 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
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,39 @@ | ||
/* | ||
* Copyright (c) 2020, 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 { Messages, Global, Mode } from '@salesforce/core'; | ||
import { UX } from '@salesforce/command'; | ||
|
||
Messages.importMessagesDirectory(__dirname); | ||
const messages = Messages.loadMessages('@salesforce/plugin-auth', 'messages'); | ||
|
||
export class Prompts { | ||
public static async shouldExitCommand(ux: UX, noPrompt?: boolean, message?: string): Promise<boolean> { | ||
if (noPrompt || Global.getEnvironmentMode() !== Mode.DEMO) { | ||
return false; | ||
} else { | ||
const answer = await ux.prompt(message || messages.getMessage('warnAuth')); | ||
return Prompts.answeredNo(answer); | ||
} | ||
} | ||
|
||
public static async shouldRunCommand(ux: UX, noPrompt?: boolean, message?: string): Promise<boolean> { | ||
if (noPrompt || Global.getEnvironmentMode() === Mode.DEMO) { | ||
return true; | ||
} else { | ||
const answer = await ux.prompt(message || messages.getMessage('warnAuth')); | ||
return Prompts.answeredYes(answer); | ||
} | ||
} | ||
|
||
private static answeredYes(answer: string): boolean { | ||
return ['YES', 'Y'].includes(answer.toUpperCase()); | ||
} | ||
|
||
private static answeredNo(answer: string): boolean { | ||
return !['YES', 'Y'].includes(answer.toUpperCase()); | ||
} | ||
} |
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