49 lines
859 B
Go
49 lines
859 B
Go
|
package opts
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
func (o *StringOption) Value() string {
|
||
|
return o.value
|
||
|
}
|