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

Improve how --output works #54

Open
mdb opened this issue Sep 27, 2019 · 6 comments
Open

Improve how --output works #54

mdb opened this issue Sep 27, 2019 · 6 comments
Labels
hacktoberfest Hacktoberfest good first issues

Comments

@mdb
Copy link
Collaborator

mdb commented Sep 27, 2019

Currently, many of the command functions have logic like this to determine the correct output. It might be good to re-imagine how this could work in a more elegant way that wouldn't require repetitive if checks in each function.

@mdb mdb added the hacktoberfest Hacktoberfest good first issues label Sep 27, 2019
@SuddenGunter
Copy link

Is it up for grabs? May I take it?

@britneywright
Copy link
Contributor

go for it @SuddenGunter 👍🏽

@SuddenGunter
Copy link

ok
I've started implementation 2 days ago here: https://github.com/SuddenGunter/vinyldns-cli
but was unable to continue since. Hope will have more time this weekend.

@SuddenGunter
Copy link

@britneywright @mdb I'm stuck, need your opinion how it would be better to approach this.
I've got 2 potential solutions at the moment:
1 extract "printing functions" with 'json' check. Something like this:
https://github.com/SuddenGunter/vinyldns-cli/commit/aa688f955e5ed2a764ef17b7de75175f21d26b6a
Pros:

  • simple
    Cons:
  • doesn't solve the issue, just hides it temporary - still would be code duplications, but a little less.

2 Use dependency injection. From my POV it would be the best approach here.
We would have some kind of a 'state' that knows how "printing subsystem" works. Basically, just a map of type->func(e element_of_type) error for each printable type we have.
When the app initializes it checks flags, and then builds that map with values. If "json" flag is present it would be simple - we have only 1 implementation for everything. If "json" flag is absent we fill map with print functions (we still would need to extract printing/formatting output logic from other code through).
Pros:

  • no code duplication
  • if tomorrow you want to add yml, xml, etc output - there are only 1 place to change + write all printing functions
  • code looks better
    Cons:
  • code is not so straight and simple to read

For 2nd approach we could use some DI package like Wire with it's codegen or dig, or do it manually - we need simple type->func mapping and one 'if' statement

@mdb
Copy link
Collaborator Author

mdb commented Oct 17, 2019

@SuddenGunter It's a bit difficult to comment in too much depth without seeing your #2 "Dependency injection" idea in implementation. Would you feel comfortable creating an implementation we could review?

Alternatively, I defer to you to assess what you think is the best candidate and we can vet it together in code review.

Taking a step back, I do think my ideal solution balances simplicity, elegance, and future scenarios where it may be desirable to add additional output formats, such as CSV, XML, etc.

@SuddenGunter
Copy link

SuddenGunter commented Oct 22, 2019

@mdb pls unassign this from me, would be able to fix it in close time
sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Hacktoberfest good first issues
Projects
None yet
Development

No branches or pull requests

3 participants