-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to dependency injection for the main CLI (#6331)
Sets up some foundations for the coming coverage sprint: - a standard way to inject dependencies into this CLI app (via `cli.App.Metadata`) - a standard way to read and write CLI text (not yet used, but hopefully the intent is clear enough) - many more error returns to cover the new branches Next steps are roughly: - write tests! - remove all `fmt.*Print*` calls and use the appropriate output writer instead - this will expose more error branches: we should be using them. standard outputs can fail if a pipe fails, and we should stop running when that occurs. - remove all stdin-reading calls, and use the input reader instead - this will allow us to answer prompts / continue paging in tests - move `ErrorAndExit`s over to error returns at some point - a lot of these really are "impossible" or are validated extremely early (CLI flags), so a panic equivalent is kinda reasonable for ergonomics - `os.Exit(1)` is much more restricting than panics, as it prevents running any defers (for printing or flushing to files) and cannot be checked in tests or suppressed for "attempt or use fallback" --- I did try to use the `cli.Context.Context` field for more "normal" dependency injection... but it ended up more annoying. The main issue it that requires using `app.RunContext(populatedContext)`, but direct access to the `*cli.App` exists _all over_ and urfave's API largely requires this. That leaves a rather large hard-to-protect error path, and it takes a few additional awkward lines of code to construct and/or pass it around. With `Metadata`, that construction can be done where all the other construction is done: inside `cli.App`-constructors. And since the `Metadata` field is _completely_ ignored by urfave's internals currently, it's basically equivalent but easier. And last but not least: if they *do* start printing Metadata some day or something, we can switch to context key(s) with relatively minimal fuss since they're both available in the same way in the same locations.
- Loading branch information
Showing
27 changed files
with
608 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.