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

vdk-control-cli: refactor output printing with printer class #1819

Merged
merged 2 commits into from
Apr 6, 2023

Conversation

antoniivanov
Copy link
Collaborator

Currently, if a command needs to print similar types of data in multiple places
or formats, the developer would have to duplicate the printing code for each location or format. This would lead to a lot of redundant code, which is difficult to maintain and prone to errors. This is making the code more "DRY".

Also, users and devs are limited to a fixed set of output formats provided by the application. This could be restricting if the devs needs to print data in a format that is not supported by the application. E.g I wanted to add rich or streamlit type potentially.

By introducing support for customizable output formats with the Printer class and related functions, users can define their own output formats and register them with the application using the printer decorator. This allows users to print data in any format they desire, providing greater flexibility and customization options.
This is of course an application of Factory and Strategy design patterns.

This is adopted in a single command here only. In a separate PR, I will adopt this printer in the other commands.

Testing Done: unit tests (incl new ones)

@antoniivanov antoniivanov force-pushed the person/aivanov/vdk-control-cli-refactor branch 2 times, most recently from 9d6b2c4 to 8229ee8 Compare April 1, 2023 20:54
Base automatically changed from person/aivanov/vdk-control-cli-more to main April 4, 2023 08:47
Copy link
Contributor

@yonitoo yonitoo left a comment

Choose a reason for hiding this comment

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

Awesome! LGTM!

@antoniivanov antoniivanov force-pushed the person/aivanov/vdk-control-cli-refactor branch 2 times, most recently from 88a56c1 to 9328713 Compare April 5, 2023 15:22
Currently if a command needs to print similar types of data in multiple
places
or formats, the developer would have to duplicate the printing code for
each location or format. This would lead to a lot of redundant code,
which is difficult to maintain and prone to errors. This is making the
code more "DRY".

Also, users and devs are limited to a fixed set of output formats
provided by the application. This could be restricting if the devs needs
to print data in a format that is not supported by the application.
E.g I wanted to add `rich` or `streamlit` type potentially.

By introducing support for customizable output formats with the Printer
class and related functions, users can define their own output formats
and register them with the application using the printer decorator. This
allows users to print data in any format they desire, providing greater
flexibility and customization options.

Testing Done: unit tests (incl new ones)

Signed-off-by: Antoni Ivanov <aivanov@vmware.com>
@antoniivanov antoniivanov force-pushed the person/aivanov/vdk-control-cli-refactor branch from 9328713 to ea36e8c Compare April 5, 2023 15:50
@antoniivanov antoniivanov enabled auto-merge (squash) April 6, 2023 10:50
@antoniivanov antoniivanov merged commit 49e301c into main Apr 6, 2023
3 of 4 checks passed
@antoniivanov antoniivanov deleted the person/aivanov/vdk-control-cli-refactor branch April 6, 2023 10:52
antoniivanov added a commit that referenced this pull request Apr 6, 2023
Adopting the new output_printer to print all outputs of all commands
that were introduced in
#1819

Some commands required small refactoring - to make some fields private.

Testing Done: existing tests to verify no regressions

Signed-off-by: Antoni Ivanov <aivanov@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants