opts/port.go:124:7: unused-receiver: method receiver 'p' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (p *PortOpt) Type() string {
^
opts/mount.go:218:7: unused-receiver: method receiver 'm' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (m *MountOpt) Type() string {
^
opts/quotedstring.go:16:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (s *QuotedString) Type() string {
^
opts/secret.go:82:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (o *SecretOpt) Type() string {
^
opts/opts_test.go:235: line-length-limit: line is 283 characters, out of limit 200 (revive)
`foo.bar.baz.this.should.fail.on.long.name.because.it.is.longer.thanisshouldbethis.should.fail.on.long.name.because.it.is.longer.thanisshouldbethis.should.fail.on.long.name.because.it.is.longer.thanisshouldbethis.should.fail.on.long.name.because.it.is.longer.thanisshouldbe`,
opts/ulimit.go:61:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (o *UlimitOpt) Type() string {
^
opts/weightdevice.go:82:7: unused-receiver: method receiver 'opt' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (opt *WeightdeviceOpt) Type() string {
^
opts/throttledevice.go:103:7: unused-receiver: method receiver 'opt' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (opt *ThrottledeviceOpt) Type() string {
^
opts/duration.go:49:7: unused-receiver: method receiver 'd' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (d *DurationOpt) Type() string {
^
opts/network.go:109:7: unused-receiver: method receiver 'n' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (n *NetworkOpt) Type() string {
^
opts/network.go:119:7: unused-receiver: method receiver 'n' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (n *NetworkOpt) String() string {
^
opts/opts.go:113:7: unused-receiver: method receiver 'opts' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (opts *ListOpts) Type() string {
^
opts/pull_behavior.go:13:7: unused-receiver: method receiver 'p' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (p *PullOpt) Type() string {
^
opts/config.go:83:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (o *ConfigOpt) Type() string {
^
opts/gpus.go:95:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (o *GpuOpts) Type() string {
^
opts/pull_behavior.go:23:7: unused-receiver: method receiver 'p' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (p *PullOpt) IsBoolFlag() bool {
^
opts/opts.go:183:7: unused-receiver: method receiver 'opts' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (opts *MapOpts) Type() string {
^
opts/opts.go:361:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (o *FilterOpt) Type() string {
^
opts/opts.go:389:7: unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (c *NanoCPUs) Type() string {
^
opts/opts.go:466:7: unused-receiver: method receiver 'm' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (m *MemBytes) Type() string {
^
opts/opts.go:501:7: unused-receiver: method receiver 'm' is not referenced in method's body, consider removing or renaming it as _ (revive)
func (m *MemSwapBytes) Type() string {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
101 lines
2.2 KiB
Go
101 lines
2.2 KiB
Go
package opts
|
|
|
|
import (
|
|
"encoding/csv"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
swarmtypes "github.com/docker/docker/api/types/swarm"
|
|
)
|
|
|
|
// ConfigOpt is a Value type for parsing configs
|
|
type ConfigOpt struct {
|
|
values []*swarmtypes.ConfigReference
|
|
}
|
|
|
|
// Set a new config value
|
|
func (o *ConfigOpt) Set(value string) error {
|
|
csvReader := csv.NewReader(strings.NewReader(value))
|
|
fields, err := csvReader.Read()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
options := &swarmtypes.ConfigReference{
|
|
File: &swarmtypes.ConfigReferenceFileTarget{
|
|
UID: "0",
|
|
GID: "0",
|
|
Mode: 0o444,
|
|
},
|
|
}
|
|
|
|
// support a simple syntax of --config foo
|
|
if len(fields) == 1 && !strings.Contains(fields[0], "=") {
|
|
options.File.Name = fields[0]
|
|
options.ConfigName = fields[0]
|
|
o.values = append(o.values, options)
|
|
return nil
|
|
}
|
|
|
|
for _, field := range fields {
|
|
key, val, ok := strings.Cut(field, "=")
|
|
if !ok || key == "" {
|
|
return fmt.Errorf("invalid field '%s' must be a key=value pair", field)
|
|
}
|
|
|
|
// TODO(thaJeztah): these options should not be case-insensitive.
|
|
switch strings.ToLower(key) {
|
|
case "source", "src":
|
|
options.ConfigName = val
|
|
case "target":
|
|
options.File.Name = val
|
|
case "uid":
|
|
options.File.UID = val
|
|
case "gid":
|
|
options.File.GID = val
|
|
case "mode":
|
|
m, err := strconv.ParseUint(val, 0, 32)
|
|
if err != nil {
|
|
return fmt.Errorf("invalid mode specified: %v", err)
|
|
}
|
|
|
|
options.File.Mode = os.FileMode(m)
|
|
default:
|
|
return fmt.Errorf("invalid field in config request: %s", key)
|
|
}
|
|
}
|
|
|
|
if options.ConfigName == "" {
|
|
return errors.New("source is required")
|
|
}
|
|
if options.File.Name == "" {
|
|
options.File.Name = options.ConfigName
|
|
}
|
|
|
|
o.values = append(o.values, options)
|
|
return nil
|
|
}
|
|
|
|
// Type returns the type of this option
|
|
func (*ConfigOpt) Type() string {
|
|
return "config"
|
|
}
|
|
|
|
// String returns a string repr of this option
|
|
func (o *ConfigOpt) String() string {
|
|
configs := []string{}
|
|
for _, config := range o.values {
|
|
repr := fmt.Sprintf("%s -> %s", config.ConfigName, config.File.Name)
|
|
configs = append(configs, repr)
|
|
}
|
|
return strings.Join(configs, ", ")
|
|
}
|
|
|
|
// Value returns the config requests
|
|
func (o *ConfigOpt) Value() []*swarmtypes.ConfigReference {
|
|
return o.values
|
|
}
|