2018-10-23 11:05:44 -04:00
|
|
|
package plugin
|
2016-11-22 19:23:21 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2018-10-23 11:05:44 -04:00
|
|
|
"github.com/docker/cli/cli/command/formatter"
|
2016-11-22 19:23:21 -05:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/pkg/stringid"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
defaultPluginTableFormat = "table {{.ID}}\t{{.Name}}\t{{.Description}}\t{{.Enabled}}"
|
|
|
|
|
2018-10-23 11:05:44 -04:00
|
|
|
enabledHeader = "ENABLED"
|
|
|
|
pluginIDHeader = "ID"
|
2016-11-22 19:23:21 -05:00
|
|
|
)
|
|
|
|
|
2018-10-23 11:05:44 -04:00
|
|
|
// NewFormat returns a Format for rendering using a plugin Context
|
|
|
|
func NewFormat(source string, quiet bool) formatter.Format {
|
2016-11-22 19:23:21 -05:00
|
|
|
switch source {
|
2018-10-23 11:05:44 -04:00
|
|
|
case formatter.TableFormatKey:
|
2016-11-22 19:23:21 -05:00
|
|
|
if quiet {
|
2018-10-23 11:05:44 -04:00
|
|
|
return formatter.DefaultQuietFormat
|
2016-11-22 19:23:21 -05:00
|
|
|
}
|
|
|
|
return defaultPluginTableFormat
|
2018-10-23 11:05:44 -04:00
|
|
|
case formatter.RawFormatKey:
|
2016-11-22 19:23:21 -05:00
|
|
|
if quiet {
|
|
|
|
return `plugin_id: {{.ID}}`
|
|
|
|
}
|
|
|
|
return `plugin_id: {{.ID}}\nname: {{.Name}}\ndescription: {{.Description}}\nenabled: {{.Enabled}}\n`
|
|
|
|
}
|
2018-10-23 11:05:44 -04:00
|
|
|
return formatter.Format(source)
|
2016-11-22 19:23:21 -05:00
|
|
|
}
|
|
|
|
|
2018-10-23 11:05:44 -04:00
|
|
|
// FormatWrite writes the context
|
|
|
|
func FormatWrite(ctx formatter.Context, plugins []*types.Plugin) error {
|
|
|
|
render := func(format func(subContext formatter.SubContext) error) error {
|
2016-11-22 19:23:21 -05:00
|
|
|
for _, plugin := range plugins {
|
|
|
|
pluginCtx := &pluginContext{trunc: ctx.Trunc, p: *plugin}
|
|
|
|
if err := format(pluginCtx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2017-02-03 19:48:46 -05:00
|
|
|
pluginCtx := pluginContext{}
|
2018-10-23 11:05:44 -04:00
|
|
|
pluginCtx.Header = formatter.SubHeaderContext{
|
2017-02-03 19:48:46 -05:00
|
|
|
"ID": pluginIDHeader,
|
2018-10-23 11:05:44 -04:00
|
|
|
"Name": formatter.NameHeader,
|
|
|
|
"Description": formatter.DescriptionHeader,
|
2017-02-03 19:48:46 -05:00
|
|
|
"Enabled": enabledHeader,
|
2018-10-23 11:05:44 -04:00
|
|
|
"PluginReference": formatter.ImageHeader,
|
2017-02-03 19:48:46 -05:00
|
|
|
}
|
|
|
|
return ctx.Write(&pluginCtx, render)
|
2016-11-22 19:23:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type pluginContext struct {
|
2018-10-23 11:05:44 -04:00
|
|
|
formatter.HeaderContext
|
2016-11-22 19:23:21 -05:00
|
|
|
trunc bool
|
|
|
|
p types.Plugin
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *pluginContext) MarshalJSON() ([]byte, error) {
|
2018-10-23 11:05:44 -04:00
|
|
|
return formatter.MarshalJSON(c)
|
2016-11-22 19:23:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *pluginContext) ID() string {
|
|
|
|
if c.trunc {
|
|
|
|
return stringid.TruncateID(c.p.ID)
|
|
|
|
}
|
|
|
|
return c.p.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *pluginContext) Name() string {
|
|
|
|
return c.p.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *pluginContext) Description() string {
|
linting: address assorted issues found by gocritic
internal/test/builders/config.go:36:15: captLocal: `ID' should not be capitalized (gocritic)
func ConfigID(ID string) func(config *swarm.Config) {
^
internal/test/builders/secret.go:45:15: captLocal: `ID' should not be capitalized (gocritic)
func SecretID(ID string) func(secret *swarm.Secret) {
^
internal/test/builders/service.go:21:16: captLocal: `ID' should not be capitalized (gocritic)
func ServiceID(ID string) func(*swarm.Service) {
^
cli/command/image/formatter_history.go:100:15: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(c.h.CreatedBy, "\t", " ", -1)` (gocritic)
createdBy := strings.Replace(c.h.CreatedBy, "\t", " ", -1)
^
e2e/image/push_test.go:246:34: badCall: suspicious Join on 1 argument (gocritic)
assert.NilError(t, os.RemoveAll(filepath.Join(dir.Join("trust"))))
^
e2e/image/push_test.go:313:34: badCall: suspicious Join on 1 argument (gocritic)
assert.NilError(t, os.RemoveAll(filepath.Join(dir.Join("trust"))))
^
cli/config/configfile/file_test.go:185:2: assignOp: replace `c.GetAllCallCount = c.GetAllCallCount + 1` with `c.GetAllCallCount++` (gocritic)
c.GetAllCallCount = c.GetAllCallCount + 1
^
cli/command/context/inspect_test.go:20:58: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(si.MetadataPath, `\`, `\\`, -1)` (gocritic)
expected = strings.Replace(expected, "<METADATA_PATH>", strings.Replace(si.MetadataPath, `\`, `\\`, -1), 1)
^
cli/command/context/inspect_test.go:21:53: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(si.TLSPath, `\`, `\\`, -1)` (gocritic)
expected = strings.Replace(expected, "<TLS_PATH>", strings.Replace(si.TLSPath, `\`, `\\`, -1), 1)
^
cli/command/container/formatter_stats.go:119:46: captLocal: `Stats' should not be capitalized (gocritic)
func statsFormatWrite(ctx formatter.Context, Stats []StatsEntry, osType string, trunc bool) error {
^
cli/command/container/stats_helpers.go:209:4: assignOp: replace `blkRead = blkRead + bioEntry.Value` with `blkRead += bioEntry.Value` (gocritic)
blkRead = blkRead + bioEntry.Value
^
cli/command/container/stats_helpers.go:211:4: assignOp: replace `blkWrite = blkWrite + bioEntry.Value` with `blkWrite += bioEntry.Value` (gocritic)
blkWrite = blkWrite + bioEntry.Value
^
cli/command/registry/formatter_search.go:67:10: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(c.s.Description, "\n", " ", -1)` (gocritic)
desc := strings.Replace(c.s.Description, "\n", " ", -1)
^
cli/command/registry/formatter_search.go:68:9: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(desc, "\r", " ", -1)` (gocritic)
desc = strings.Replace(desc, "\r", " ", -1)
^
cli/command/service/list_test.go:164:5: assignOp: replace `tc.doc = tc.doc + " with quiet"` with `tc.doc += " with quiet"` (gocritic)
tc.doc = tc.doc + " with quiet"
^
cli/command/service/progress/progress.go:274:11: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(errMsg, "\n", " ", -1)` (gocritic)
errMsg = strings.Replace(errMsg, "\n", " ", -1)
^
cli/manifest/store/store.go:153:9: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(fileName, "/", "_", -1)` (gocritic)
return strings.Replace(fileName, "/", "_", -1)
^
cli/manifest/store/store.go:152:14: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(ref, ":", "-", -1)` (gocritic)
fileName := strings.Replace(ref, ":", "-", -1)
^
cli/command/plugin/formatter.go:79:10: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(c.p.Config.Description, "\n", "", -1)` (gocritic)
desc := strings.Replace(c.p.Config.Description, "\n", "", -1)
^
cli/command/plugin/formatter.go:80:9: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(desc, "\r", "", -1)` (gocritic)
desc = strings.Replace(desc, "\r", "", -1)
^
cli/compose/convert/service.go:642:23: captLocal: `DNS' should not be capitalized (gocritic)
func convertDNSConfig(DNS []string, DNSSearch []string) *swarm.DNSConfig {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-11-20 07:30:05 -05:00
|
|
|
desc := strings.ReplaceAll(c.p.Config.Description, "\n", "")
|
|
|
|
desc = strings.ReplaceAll(desc, "\r", "")
|
2016-11-22 19:23:21 -05:00
|
|
|
if c.trunc {
|
2018-10-23 11:05:44 -04:00
|
|
|
desc = formatter.Ellipsis(desc, 45)
|
2016-11-22 19:23:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return desc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *pluginContext) Enabled() bool {
|
|
|
|
return c.p.Enabled
|
|
|
|
}
|
2017-01-28 19:54:32 -05:00
|
|
|
|
|
|
|
func (c *pluginContext) PluginReference() string {
|
|
|
|
return c.p.PluginReference
|
|
|
|
}
|