gh-gei icon indicating copy to clipboard operation
gh-gei copied to clipboard

Move validations into the arg class

Open ArinGhazarian opened this issue 3 years ago • 0 comments

Currently we perform the arg validations inside the command handler class sometimes right inside the handle method or in its own dedicated method (or more than one method even).

The problems with this approach are:

  1. We do the validations after we create the handler which is not ideal. We shouldn't even create the handler if the validation fails.
  2. There is no uniform pattern for validations. Sometimes we do them in a single place or sometimes they are scattered in a handler class inside different methods which makes it harder to keep a track and make changes, also there is a possibility of missing some.

Todo

  • [ ] Create a Validate method inside each arg class (it can come from a base arg class and be overridden in the arg class) and put all arg validations in it.
  • [ ] Remove the validations from the command handler classes and call the Validate method in the command class as part of the BuildHandler method.
  • [ ] Rethink about arg validations case by case specially for larger commands like migrate-repo or generate-script. Like for example in bb2gh migrate-repo command if we don't pass the --github-org and --github-repo our code is not going to work properly, so we need to reconsider all possible scenarios and write appropriate tests to cover them.

ArinGhazarian avatar Oct 26 '22 20:10 ArinGhazarian