Skip to content

Commit

Permalink
feat(cli): improve UX of multi-item selection
Browse files Browse the repository at this point in the history
When asking the user to select 1 or more items, e.g. models to import,
require at least one item to be selected.

This prevents users from accidentally pressing ENTER instead of SPACE
to select an item from the list, in which case the prompt is resolved
with an empty list and thus the CLI command ends prematurely.

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
  • Loading branch information
bajtos committed Nov 12, 2019
1 parent 5806447 commit 077f38c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/cli/generators/discover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
when:
this.discoveringModels === undefined &&
!this.artifactInfo.modelDefinitions,
// Require at least one model to be selected
// This prevents users from accidentally pressing ENTER instead of SPACE
// to select a model from the list
validate: result => !!result.length,
},
];

Expand Down
3 changes: 3 additions & 0 deletions packages/cli/generators/import-lb3-models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Learn more at https://loopback.io/doc/en/lb4/Importing-LB3-models.html
message: 'Select models to import:',
type: 'checkbox',
choices: modelNames,
// Require at least one model to be selected
// This prevents users from accidentally pressing ENTER instead of SPACE
// to select a model from the list
validate: result => !!result.length,
// TODO: add a CLI flag to supply these names programmatically
},
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/generators/openapi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ module.exports = class OpenApiGenerator extends BaseGenerator {
message: 'Select controllers to be generated:',
type: 'checkbox',
choices: choices,
// Require at least one item to be selected
// This prevents users from accidentally pressing ENTER instead of SPACE
// to select an item from the list
validate: result => !!result.length,
},
];
const selections =
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/generators/repository/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ module.exports = class RepositoryGenerator extends ArtifactGenerator {
message: PROMPT_MESSAGE_MODEL,
choices: modelList,
when: this.artifactInfo.modelNameList === undefined,
// Require at least one model to be selected
// This prevents users from accidentally pressing ENTER instead of SPACE
// to select a model from the list
validate: result => !!result.length,
},
])
.then(props => {
Expand Down

0 comments on commit 077f38c

Please sign in to comment.