-
Notifications
You must be signed in to change notification settings - Fork 92
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
General clean up of testdbman
program + drop Cobra dependency
#266
Conversation
@bgentry This one low priority, but just as a general nicety. |
1cde1e3
to
dfb420a
Compare
internal/cmd/testdbman/main.go
Outdated
// This is the same default as pgxpool's maximum number of connections | ||
// when not specified -- either 4 or the number of CPUs, whichever is | ||
// greater. If changing this number, also change the similar value in | ||
// `riverinternaltest` where it's duplicated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is probably better placed above line 138 where the numDBs
is calculated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah whoops. Good call. Moved.
This one's mainly in pursuit of dropping the Cobra dependency in the main River package. It's still nice to have Cobra for the River CLI, but the only reason that top-level River needs it is that `testdbman` (the command used to drop and raise test databases needs it). Since `testdbman`'s CLI API is so simple anyway, here we move it off of Cobra and over to a small internal CLI framework, maintaining an identical interface as before (with the small change that `--help` is now `-help` since we're using Go's internal flag module). This would normally be a dumb thing to do, but I don't expect the `testdbman` interface to have to get anymore complicated (it hasn't changed at all since River's inception), the internal framework isn't a huge amount of code, and I put some test coverage on it to make sure that everything works as expected. In addition to that, we do a little housekeeping on the internal code for `testdbman`: * Reduce visual noise by stripping extra lines and functions that were doing very little, and removing some specific contexts in favor of one top-level one for the program. * Move the core functions and command definitions into one file so that quick file find works a little better and it's easier to get a holistic view of what everything is doing. Especially after trimming code, there's so little code that it all fits together without feeling crowded, and previously some of the files like `reset.go` were doing practically nothing. * A single unified error handling schema. Previously some code was printing to stderr and aborting the program and some code was returning errors. Now everything returns an error with a single top-level error handler. * Make output and error formatting more consistent across commands. * Tighten up some documentation and comments that'd fallen out of date since the program was originally written. * Remove some helper functions like `dbURL` that were doing more to obscure than to help (it had a special path for the management database URL and then did a string concatenation otherwise, but it's much more clear to just use a constant for the management database URL when we know that we want it). Add helpers where appropriate like `generateTestDBNames` that let us put a little (very modest amount for the time being) test coverage onto the program.
dfb420a
to
ba0d6e3
Compare
This one's mainly in pursuit of dropping the Cobra dependency in the
main River package. It's still nice to have Cobra for the River CLI, but
the only reason that top-level River needs it is that
testdbman
(thecommand used to drop and raise test databases needs it). Since
testdbman
's CLI API is so simple anyway, here we move it off of Cobraand over to a small internal CLI framework, maintaining an identical
interface as before (with the small change that
--help
is now-help
since we're using Go's internal flag module).
This would normally be a dumb thing to do, but I don't expect the
testdbman
interface to have to get anymore complicated (it hasn'tchanged at all since River's inception), the internal framework isn't a
huge amount of code, and I put some test coverage on it to make sure
that everything works as expected.
In addition to that, we do a little housekeeping on the internal code
for
testdbman
:Reduce visual noise by stripping extra lines and functions that were
doing very little, and removing some specific contexts in favor of one
top-level one for the program.
Move the core functions and command definitions into one file so that
quick file find works a little better and it's easier to get a
holistic view of what everything is doing. Especially after trimming
code, there's so little code that it all fits together without feeling
crowded, and previously some of the files like
reset.go
were doingpractically nothing.
A single unified error handling schema. Previously some code was
printing to stderr and aborting the program and some code was
returning errors. Now everything returns an error with a single
top-level error handler.
Make output and error formatting more consistent across commands.
Tighten up some documentation and comments that'd fallen out of date
since the program was originally written.
Remove some helper functions like
dbURL
that were doing more toobscure than to help (it had a special path for the management
database URL and then did a string concatenation otherwise, but it's
much more clear to just use a constant for the management database URL
when we know that we want it). Add helpers where appropriate like
generateTestDBNames
that let us put a little (very modest amount forthe time being) test coverage onto the program.