2023-11-12 17:19:34 -05:00
|
|
|
package opt
|
2023-11-11 19:28:58 -05:00
|
|
|
|
|
|
|
import "strconv"
|
|
|
|
|
|
|
|
type IntOption struct {
|
|
|
|
name string
|
|
|
|
shortName string
|
|
|
|
description string
|
|
|
|
value int
|
|
|
|
}
|
|
|
|
|
2023-11-11 20:49:38 -05:00
|
|
|
var _ Option = (*IntOption)(nil)
|
2023-11-11 19:28:58 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-11-12 17:07:38 -05:00
|
|
|
// RequiresVal implements Option.
|
|
|
|
func (*IntOption) RequiresVal() bool {
|
2023-11-11 20:49:38 -05:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-11-11 19:28:58 -05:00
|
|
|
func (o *IntOption) Value() int {
|
|
|
|
return o.value
|
|
|
|
}
|