Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace command inputs and options by a dictionary-like high-level data abstraction #2180

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

micalevisk
Copy link
Member

@micalevisk micalevisk commented Jul 16, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[x] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

I notice that all operations on command's inputs and options are using .find() to search for the first input/option found

What is the new behavior?

replace the usage of Input[] from .command.ts and .action.ts files by a new abstraction called CommandContext which hides the complexity of registering and retrieving some input/operation in a command lifecycle.

this change is intended to improve:

  • code readability
    Instead of having a bunch of calls like inputs.find((o) => o.name === 'foo') we now have just one inputs.resolveInput('foo'), which is also slightly fast as it uses JS Map under the hood. This make it even clear that we shouldn't be define the same input name more than one time. I didn't write a validation for this scenario for [micro]performance sake but we could easily introduce that if needed
  • type safety
    Instead of relying on type assertion and non-null assertions, we're using generics to make the code less error prone at compile time. The present solution doesn't differ that much from type assertions but there is a room to improve that easily by now

Does this PR introduce a breaking change?

[ ] Yes
[x] No

@micalevisk micalevisk force-pushed the refactor/proper-abstraction-to-command-inputs branch from 6f77e3e to fcda32b Compare July 16, 2023 21:45
@micalevisk micalevisk changed the title refactor: replace command inputs and options by a dictionary-like data type abstraction refactor: replace command inputs and options by a dictionary-like high-level data abstraction Jul 16, 2023
@kamilmysliwiec
Copy link
Member

kamilmysliwiec commented Jul 17, 2023

I'd love to finally get rid of these confusing Input/Option abstractions - these are leftovers from the first version of the CLI 😄

@micalevisk micalevisk marked this pull request as ready for review July 22, 2023 20:48
@micalevisk micalevisk force-pushed the refactor/proper-abstraction-to-command-inputs branch from 6c02d94 to 519ecbf Compare July 22, 2023 21:18
@micalevisk
Copy link
Member Author

micalevisk commented Jul 22, 2023

in order to try this version better, I've published this branch's version as
micalevisk-nestjs-cli package. I've tested all the commands (but not all the flags, of course)

@micalevisk micalevisk marked this pull request as draft July 22, 2023 21:29
@micalevisk micalevisk marked this pull request as ready for review July 22, 2023 21:48
@micalevisk micalevisk force-pushed the refactor/proper-abstraction-to-command-inputs branch from 384326a to 4507fbb Compare July 22, 2023 22:41
@micalevisk micalevisk marked this pull request as draft July 22, 2023 22:42
@micalevisk micalevisk force-pushed the refactor/proper-abstraction-to-command-inputs branch from 4507fbb to 519ecbf Compare July 22, 2023 22:43
- emit error on retrieve inputs with 'undefined' value
- leave 'project' option optional as before
- leave 'collection' optional as before
- allow 'specFileSuffix' to be undefined
- allow 'config' option to be undefined on build command
@micalevisk micalevisk marked this pull request as ready for review July 22, 2023 22:44
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.

None yet

2 participants