Skip to content

Design Guidelines Interactivity

Matt Graham edited this page Apr 28, 2023 · 1 revision

Interactive commands are a powerful way to develop a great experience for your users. Our goal is to make Salesforce CLI approachable to all users, and interactivity helps make this possible. Keep these general guidelines in mind when implementing interactive prompts.

Ask as Few Questions as Possible

We recommend that you ask as few questions as possible so as to not overwhelm your users. Asking users dozens of questions all at once can cause decision fatigue and lead to a poor experience. Instead, ask the most meaningful and necessary questions to gather the information you need.

Scripting

Many Salesforce CLI users leverage the --json flag to write scripts for their continuous integration (CI) environments. These users often load the JSON response into a JSON parsing utility like jq. As a result, the JSON output in stdout must be parsable or else these users' scripts fail.

If you implement a prompt on a command that supports --json, the resulting JSON isn't parsable because the prompts are part of the stdout.

We recommend one of the following:

  • Develop commands that are either interactive or scriptable (support --json), but not both. In other words, if you plan for a command to be interactive, then disable the --json flag by setting enableJsonFlag = false on the command class that extends SfCommand.

  • If you require a command that is both interactive and scriptable, then add flags that supply the same information gathered by the interactive prompt. You must use this.jsonEnabled before starting the prompt so that you don't accidentally prompt the user when they provide the --json flag.

Clone this wiki locally