2015-02-11 14:21:38 -05:00
|
|
|
package opts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2015-12-21 15:06:46 -05:00
|
|
|
"github.com/docker/go-units"
|
2015-02-11 14:21:38 -05:00
|
|
|
)
|
|
|
|
|
2015-07-21 12:15:36 -04:00
|
|
|
// UlimitOpt defines a map of Ulimits
|
2015-02-11 14:21:38 -05:00
|
|
|
type UlimitOpt struct {
|
2015-12-21 15:06:46 -05:00
|
|
|
values *map[string]*units.Ulimit
|
2015-02-11 14:21:38 -05:00
|
|
|
}
|
|
|
|
|
2015-07-21 12:15:36 -04:00
|
|
|
// NewUlimitOpt creates a new UlimitOpt
|
2015-12-21 15:06:46 -05:00
|
|
|
func NewUlimitOpt(ref *map[string]*units.Ulimit) *UlimitOpt {
|
2015-05-05 00:18:28 -04:00
|
|
|
if ref == nil {
|
2015-12-21 15:06:46 -05:00
|
|
|
ref = &map[string]*units.Ulimit{}
|
2015-05-05 00:18:28 -04:00
|
|
|
}
|
2015-02-11 14:21:38 -05:00
|
|
|
return &UlimitOpt{ref}
|
|
|
|
}
|
|
|
|
|
2015-07-21 12:15:36 -04:00
|
|
|
// Set validates a Ulimit and sets its name as a key in UlimitOpt
|
2015-02-11 14:21:38 -05:00
|
|
|
func (o *UlimitOpt) Set(val string) error {
|
2015-12-21 15:06:46 -05:00
|
|
|
l, err := units.ParseUlimit(val)
|
2015-02-11 14:21:38 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
(*o.values)[l.Name] = l
|
2015-02-11 14:21:38 -05:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-21 12:15:36 -04:00
|
|
|
// String returns Ulimit values as a string.
|
2015-02-11 14:21:38 -05:00
|
|
|
func (o *UlimitOpt) String() string {
|
|
|
|
var out []string
|
2015-05-05 00:18:28 -04:00
|
|
|
for _, v := range *o.values {
|
2015-02-11 14:21:38 -05:00
|
|
|
out = append(out, v.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%v", out)
|
|
|
|
}
|
|
|
|
|
2015-07-21 12:15:36 -04:00
|
|
|
// GetList returns a slice of pointers to Ulimits.
|
2015-12-21 15:06:46 -05:00
|
|
|
func (o *UlimitOpt) GetList() []*units.Ulimit {
|
|
|
|
var ulimits []*units.Ulimit
|
2015-05-05 00:18:28 -04:00
|
|
|
for _, v := range *o.values {
|
2015-02-11 14:21:38 -05:00
|
|
|
ulimits = append(ulimits, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ulimits
|
|
|
|
}
|
2016-05-31 19:49:32 -04:00
|
|
|
|
|
|
|
// Type returns the option type
|
|
|
|
func (o *UlimitOpt) Type() string {
|
|
|
|
return "ulimit"
|
|
|
|
}
|