Adds prompting on invalid option sets in Zod-enabled commands#7061
Adds prompting on invalid option sets in Zod-enabled commands#7061waldekmastykarz wants to merge 5 commits intopnp:mainfrom
Conversation
|
To test, run:
Notice the additional information that we'll need in refined schema definition to feed prompts. Let's verify that this approach works and meets all our needs. I'll then add the necessary tests and fix existing Zod-enabled commands to support this properly. |
|
Let's continue with this after we merge #7005 so that we do the migration/alignment work once. |
e44a046 to
5b7f650
Compare
@waldekmastykarz this one got merged so I think we may continue. |
5b7f650 to
ff328b7
Compare
There was a problem hiding this comment.
Pull request overview
This PR implements interactive prompting for invalid option sets in Zod-enabled commands to maintain UX consistency with non-Zod commands. When users provide invalid option combinations (e.g., specifying both mutually exclusive options or none of the required options), the CLI now prompts them to select and provide values for the correct options instead of immediately exiting with an error.
Changes:
- Added prompting logic in
src/cli/cli.tsto detect and handle option set validation errors from Zod schemas by checking for custom error params withcustomCode: 'optionSet' - Modified error handling in
src/index.tsto catchExitPromptErrorat the top level (moved fromsrc/utils/prompt.ts) - Updated 50+ command files to add
paramsmetadata to their Zod.refine()calls, marking them as eitheroptionSetorrequiredvalidation errors for proper prompting behavior
Reviewed changes
Copilot reviewed 53 out of 53 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/index.ts | Added top-level ExitPromptError handling to exit gracefully when user cancels prompts |
| src/utils/prompt.ts | Removed ExitPromptError catch block from prompt.forInput (now handled at top level) |
| src/cli/cli.ts | Implemented option set prompting logic that classifies validation errors and prompts users to select and provide values for option sets |
| src/cli/cli.spec.ts | Added comprehensive tests for option set prompting, required field prompting, and error handling with refined schemas |
| src/m365/viva/commands/engage/*.ts | Added optionSet params to refine() calls for community and role option validations |
| src/m365/teams/commands/callrecord/callrecord-list.ts | Added optionSet params for userId/userName validation |
| src/m365/spp/commands/**/*.ts | Added optionSet params for model and autofill column option validations |
| src/m365/spo/commands/**/*.ts | Added optionSet/required params for list, page, homesite, file, and web alert option validations |
| src/m365/spe/commands/**/*.ts | Added optionSet params for container and containertype option validations |
| src/m365/pp/commands/**/*.ts | Added optionSet params for website and environment option validations |
| src/m365/pa/commands/environment/environment-get.ts | Added optionSet params for name/default validation |
| src/m365/outlook/commands/**/*.ts | Added optionSet/required params for mailbox and mail searchfolder option validations |
| src/m365/graph/commands/directoryextension/*.ts | Added optionSet params for directory extension option validations |
| src/m365/flow/commands/environment/environment-get.ts | Added optionSet params for name/default validation |
| src/m365/exo/commands/approleassignment/approleassignment-add.ts | Added optionSet params for extensive role and scope option validations |
| src/m365/entra/commands/**/*.ts | Added optionSet/required params for user, role, admin unit, and organization option validations |
| src/m365/commands/login.ts | Added optionSet/required params for authentication option validations |
| src/m365/booking/commands/business/business-get.ts | Added optionSet params for id/name validation |
| src/m365/app/commands/permission/permission-add.ts | Added required params for permission option validation |
| src/m365/adaptivecard/commands/adaptivecard-send.ts | Added required params for card option validation |
Jwaegebaert
left a comment
There was a problem hiding this comment.
Great work @waldekmastykarz! Left a few minor suggestion and the topic Copilot suggested seems something interesting to look into. That function works fine for strings but as soon as we work with other types the behavior seems to change a bit.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Adds prompting on invalid option sets in Zod-enabled commands. Closes #7060