Rename TakesArg to RequiresVal

This commit is contained in:
Evan Fiordeliso 2023-11-12 17:07:38 -05:00
parent b8a7d72433
commit 753c179edb
6 changed files with 12 additions and 12 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -7,7 +7,7 @@ type Option interface {
ShortName() string
Description() string
Parse(raw string) error
TakesArg() bool
RequiresVal() bool
}
func Names(o Option) string {

View File

@ -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))
}

View File

@ -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
}