cli-plugins/manager: minor cleanups and refactoring#5936
cli-plugins/manager: minor cleanups and refactoring#5936thaJeztah merged 5 commits intodocker:masterfrom
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
Oh! Ignore me; It's the context that's |
This error-group was added in 89583b9, but passed a context.TODO because the function didn't have a context as argument. However, it does get the root-command passed, which holds the context, so we can pass that. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Verify that listPluginCandidates returns an empty result if nothing was found. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Skip the other logic, which includes listing all commands provided; if there's no plugin-candidates, those steps won't be needed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This function returned an error (if any) from [config.Path]. However, the only situation in which an error could be returned was if the given path to append to `config.Dir` was outside of the config directory. This can only happen if the path to append would try to traverse directories (e.g., passing `../../cli-plugins`). Given that we're passing a hard-coded value, that would not be the case, so we can simplify the code to join the path directly, and don't have to handle errors. [config.Path]: https://github.com/docker/cli/blob/2d74733942be353bc7730c8722ae2414f368b732/cli/config/config.go#L100-L107 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
60ef134 to
091421f
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5936 +/- ##
==========================================
+ Coverage 59.33% 59.38% +0.04%
==========================================
Files 358 358
Lines 29783 29776 -7
==========================================
+ Hits 17672 17681 +9
+ Misses 11142 11127 -15
+ Partials 969 968 -1 🚀 New features to boost your workflow:
|
| if ctx == nil { | ||
| // Fallback, mostly for tests that pass a bare cobra.command | ||
| ctx = context.Background() | ||
| } | ||
| eg, _ := errgroup.WithContext(ctx) |
There was a problem hiding this comment.
maybe we should instead force the tests to set a context?
There was a problem hiding this comment.
Yeah, I originally updated the test, but given that this function is exported, I could not 100% exclude the possibility for other code to call this with a command that has not (yet?) has a context set.
Without a context, this produces a panic at runtime, which was a bit risky, so ultimately I chose for making this "best effort", and keep the test as-is to verify that things work even if no context is present on the command.
There was a problem hiding this comment.
Ah i see, alright then let's get this one merged.
cli-plugins/manager: ListPlugins: pass context to error-group
This error-group was added in 89583b9, but
passed a context.TODO because the function didn't have a context as argument.
However, it does get the root-command passed, which holds the context, so
we can pass that.
cli-plugins/manager: rename var that shadowed arg in test
cli-plugins/manager: add test for empty / non-existing plugin dirs
Verify that listPluginCandidates returns an empty result if nothing was
found.
cli-plugins/manager: ListPlugins: return early if no candidates
Skip the other logic, which includes listing all commands provided; if
there's no plugin-candidates, those steps won't be needed.
cli-plugins/manager: getPluginDirs: remove redundant error-return
This function returned an error (if any) from config.Path. However, the
only situation in which an error could be returned was if the given path
to append to
config.Dirwas outside of the config directory. This canonly happen if the path to append would try to traverse directories (e.g.,
passing
../../cli-plugins).Given that we're passing a hard-coded value, that would not be the case,
so we can simplify the code to join the path directly, and don't have to
handle errors.
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)