cmd/opt/option.go

36 lines
679 B
Go

package opt
import "fmt"
type Option interface {
Name() string
ShortName() string
Description() string
Parse(raw string) error
RequiresVal() bool
}
func Names(o Option) string {
names := ""
if o.ShortName() != "" {
names += fmt.Sprintf("-%s, ", o.ShortName())
}
names += fmt.Sprintf("--%s", o.Name())
return names
}
func HelpLine(o Option, paddedWidth int) string {
argNames := ""
if o.ShortName() != "" {
argNames += fmt.Sprintf("-%s, ", o.ShortName())
}
argNames += fmt.Sprintf("--%s", o.Name())
spaceSize := paddedWidth - len(argNames)
if spaceSize > 0 {
argNames += fmt.Sprintf("%*s", spaceSize, "")
}
return argNames + " " + o.Description()
}