Rename TakesArg to RequiresVal
This commit is contained in:
parent
b8a7d72433
commit
753c179edb
|
@ -54,8 +54,8 @@ func (o *BoolOption) Parse(raw string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// TakesArg implements Option.
|
||||
func (*BoolOption) TakesArg() bool {
|
||||
// RequiresVal implements Option.
|
||||
func (*BoolOption) RequiresVal() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -51,8 +51,8 @@ func (o *FloatOption) Parse(raw string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// TakesArg implements Option.
|
||||
func (*FloatOption) TakesArg() bool {
|
||||
// RequiresVal implements Option.
|
||||
func (*FloatOption) RequiresVal() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -51,8 +51,8 @@ func (o *IntOption) Parse(raw string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// TakesArg implements Option.
|
||||
func (*IntOption) TakesArg() bool {
|
||||
// RequiresVal implements Option.
|
||||
func (*IntOption) RequiresVal() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ type Option interface {
|
|||
ShortName() string
|
||||
Description() string
|
||||
Parse(raw string) error
|
||||
TakesArg() bool
|
||||
RequiresVal() bool
|
||||
}
|
||||
|
||||
func Names(o Option) string {
|
||||
|
|
|
@ -109,7 +109,7 @@ func (p *Parser) parseLongOption(longName string) error {
|
|||
return nil // Ignore unknown option. Continue parsing.
|
||||
}
|
||||
|
||||
if value == "" && opt.TakesArg() {
|
||||
if value == "" && opt.RequiresVal() {
|
||||
var ok bool
|
||||
value, ok = p.value()
|
||||
if !ok {
|
||||
|
@ -137,7 +137,7 @@ func (p *Parser) parseShortOption(shortNames string) error {
|
|||
return nil // Ignore unknown option. Continue parsing.
|
||||
}
|
||||
|
||||
if !valOk && opt.TakesArg() {
|
||||
if !valOk && opt.RequiresVal() {
|
||||
return fmt.Errorf("%w: %s", ErrOptionRequiresValue, "-"+shortNames)
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ func (p *Parser) parseShortOption(shortNames string) error {
|
|||
continue // Ignore unknown option. Continue parsing.
|
||||
}
|
||||
|
||||
if opt.TakesArg() {
|
||||
if opt.RequiresVal() {
|
||||
if j > 0 {
|
||||
return fmt.Errorf("%w: %s", ErrCannotChainOption, "-"+string(shortName))
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ func (o *StringOption) Parse(raw string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// TakesArg implements Option.
|
||||
func (*StringOption) TakesArg() bool {
|
||||
// RequiresVal implements Option.
|
||||
func (*StringOption) RequiresVal() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue