package opt import "strconv" type IntOption struct { name string shortName string description string value int } var _ Option = (*IntOption)(nil) func Int(name, shortName string, defaultValue int, description string) *IntOption { return &IntOption{ name: name, shortName: shortName, description: description, value: defaultValue, } } // Description implements Option. func (o *IntOption) Description() string { return o.description } // Name implements Option. func (o *IntOption) Name() string { return o.name } // ShortName implements Option. func (o *IntOption) ShortName() string { return o.shortName } // Value implements Option. func (o *IntOption) Parse(raw string) error { if raw == "" { return nil } intVal, err := strconv.Atoi(raw) if err != nil { return err } o.value = intVal return nil } // RequiresVal implements Option. func (*IntOption) RequiresVal() bool { return true } func (o *IntOption) Value() int { return o.value }