Skip to content

Adds prompting on invalid option sets in Zod-enabled commands#7061

Open
waldekmastykarz wants to merge 5 commits intopnp:mainfrom
waldekmastykarz:zod-optionset-prompt
Open

Adds prompting on invalid option sets in Zod-enabled commands#7061
waldekmastykarz wants to merge 5 commits intopnp:mainfrom
waldekmastykarz:zod-optionset-prompt

Conversation

@waldekmastykarz
Copy link
Copy Markdown
Member

@waldekmastykarz waldekmastykarz commented Dec 6, 2025

Adds prompting on invalid option sets in Zod-enabled commands. Closes #7060

@waldekmastykarz
Copy link
Copy Markdown
Member Author

To test, run:

  • m365 login -t password > input prompts for username and password
  • m365 login -t certificate > selection prompt for the cert option
  • possible to abort prompt and close the CLI without an exception, by pressing CTRL+C

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.

@waldekmastykarz
Copy link
Copy Markdown
Member Author

Let's continue with this after we merge #7005 so that we do the migration/alignment work once.

@Adam-it
Copy link
Copy Markdown
Member

Adam-it commented Jan 4, 2026

Let's continue with this after we merge #7005 so that we do the migration/alignment work once.

@waldekmastykarz this one got merged so I think we may continue.
I also tested this PR locally, and this is exactly what we need to recreate 👍

@waldekmastykarz waldekmastykarz changed the title WIP: Adds prompting on invalid option sets in Zod-enabled commands Adds prompting on invalid option sets in Zod-enabled commands Feb 22, 2026
@waldekmastykarz waldekmastykarz marked this pull request as ready for review February 22, 2026 09:47
@Jwaegebaert Jwaegebaert requested a review from Copilot February 23, 2026 13:56
@Jwaegebaert Jwaegebaert self-assigned this Feb 23, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts to detect and handle option set validation errors from Zod schemas by checking for custom error params with customCode: 'optionSet'
  • Modified error handling in src/index.ts to catch ExitPromptError at the top level (moved from src/utils/prompt.ts)
  • Updated 50+ command files to add params metadata to their Zod .refine() calls, marking them as either optionSet or required validation 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

Comment thread src/cli/cli.ts Outdated
Copy link
Copy Markdown
Contributor

@Jwaegebaert Jwaegebaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/cli/cli.ts Outdated
Comment thread src/cli/cli.ts Outdated
waldekmastykarz and others added 3 commits March 28, 2026 15:09
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 53 out of 53 changed files in this pull request and generated 12 comments.

Comment thread src/cli/cli.ts
Comment thread src/cli/cli.ts
Comment thread src/index.ts
Comment thread src/m365/adaptivecard/commands/adaptivecard-send.ts
Comment thread src/m365/spo/commands/list/list-view-add.ts
Comment thread src/m365/spo/commands/homesite/homesite-set.ts
Comment thread src/m365/outlook/commands/mailbox/mailbox-settings-set.ts
Comment thread src/m365/entra/commands/roledefinition/roledefinition-set.ts
Comment thread src/m365/entra/commands/organization/organization-set.ts
Comment thread src/m365/viva/commands/engage/engage-community-user-remove.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add prompting on invalid option sets in Zod-enabled commands

4 participants