Skip to content

Migrate 'entra multitenant add' to ZodΒ #6906

@martinlingstuyl

Description

@martinlingstuyl

Introduction

As CLI team, we're doing a major refactoring of the code base on how we validate incoming options. In the new situation, we're now using Zod. The idea is that we define options as a Zod schema, and parse/validate the incoming options using that schema. This is a major change that needs to be done on every command in the CLI codebase and as such is a lot of work. But you can help πŸ’ͺ...

This issue

Refactor the 'entra multitenant add' command to use Zod for schema validation.

Implementation

There's some reference material for migrating to Zod. Check out the entra administrativeunit <verb> commands for that. There's a couple of things that are important:

  • Define an options object, based on globalOptionsZod.
  • Implement the schema function in the command class to return the options object.
  • Add any options to the schema if options are currently defined on the command
  • Add refinements if necessary for additional validation.
  • Remove the command class constructor and all its functions
  • Update the test file with the schema and safeParse() / parse() function calls.

Do check out our reference implementations to see what we mean here.

Help by Copilot

If you are able to use Github Copilot, you may do so. There's a prompt file that's available to use for migration (.github\prompts\migrate-command-to-zod.prompt.md) You can let Copilot work on a command using the prompt file. Some tips here:

  • Use a Claude Sonnet model, not a GPT model.
  • Check the changes afterwards, Copilot may forget things are change too much.

Good luck! πŸŽ‰πŸ’ͺ

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions