54 lines
950 B
Go
54 lines
950 B
Go
package opt
|
|
|
|
type StringOption struct {
|
|
name string
|
|
shortName string
|
|
description string
|
|
value string
|
|
}
|
|
|
|
var _ Option = (*StringOption)(nil)
|
|
|
|
func String(name, shortName, defaultValue, description string) *StringOption {
|
|
return &StringOption{
|
|
name: name,
|
|
shortName: shortName,
|
|
description: description,
|
|
value: defaultValue,
|
|
}
|
|
}
|
|
|
|
// Description implements Option.
|
|
func (o *StringOption) Description() string {
|
|
return o.description
|
|
}
|
|
|
|
// Name implements Option.
|
|
func (o *StringOption) Name() string {
|
|
return o.name
|
|
}
|
|
|
|
// ShortName implements Option.
|
|
func (o *StringOption) ShortName() string {
|
|
return o.shortName
|
|
}
|
|
|
|
// Value implements Option.
|
|
func (o *StringOption) Parse(raw string) error {
|
|
if raw == "" {
|
|
return nil
|
|
}
|
|
|
|
o.value = raw
|
|
return nil
|
|
}
|
|
|
|
// RequiresVal implements Option.
|
|
func (*StringOption) RequiresVal() bool {
|
|
return true
|
|
}
|
|
|
|
func (o *StringOption) Value() string {
|
|
return o.value
|
|
}
|