Skip to content

Commit 9325743

Browse files
committed
cli/command/system: needsServerInfo: add fast-paths
We can return early without executing the regular expression or evaluating the template for `--format=json` or `--format='{{json .}}'`. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent ac375ca commit 9325743

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

cli/command/system/info.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,16 @@ var placeHolders = regexp.MustCompile(`\.[a-zA-Z]`)
149149
// connecting to the daemon. This allows (e.g.) to only get cli-plugin
150150
// information, without also making a (potentially expensive) API call.
151151
func needsServerInfo(template string, info dockerInfo) bool {
152-
if len(template) == 0 || placeHolders.FindString(template) == "" {
153-
// The template is empty, or does not contain formatting fields
154-
// (e.g. `table` or `raw` or `{{ json .}}`). Assume we need server-side
155-
// information to render it.
152+
switch template {
153+
case "", formatter.JSONFormat, formatter.JSONFormatKey:
154+
// No format (default) and full JSON output need server-side info.
156155
return true
156+
default:
157+
if placeHolders.FindString(template) == "" {
158+
// The template does not contain formatting fields; assume we
159+
// need server-side information to render it, and return early.
160+
return true
161+
}
157162
}
158163

159164
// A template is provided and has at least one field set.

0 commit comments

Comments
 (0)