github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/spec/features/feature.go (about)

     1  package features
     2  
     3  import (
     4  	"github.com/metux/go-metabuild/util/specobj"
     5  )
     6  
     7  type Feature struct {
     8  	specobj.SpecObj
     9  	Id Key
    10  }
    11  
    12  func (f Feature) Value() string {
    13  	return f.EntryStr(KeyEnabled)
    14  }
    15  
    16  func (f Feature) ValueYN() string {
    17  	switch v := f.Value(); v {
    18  	case "true", "yes", "1":
    19  		return "y"
    20  	case "false", "no", "0", "":
    21  		return "n"
    22  	default:
    23  		return v
    24  	}
    25  }
    26  
    27  func (f Feature) IsOn() bool {
    28  	switch v := f.Value(); v {
    29  	case "y", "true", "yes", "1":
    30  		return true
    31  	case "n", "false", "no", "0", "":
    32  		return false
    33  	}
    34  	return false
    35  }
    36  
    37  func (f Feature) Set(v string) {
    38  	f.EntryPutStr(KeyEnabled, v)
    39  }
    40  
    41  func (f Feature) SetOn() {
    42  	f.Set("on")
    43  }
    44  
    45  func (f Feature) SetOff() {
    46  	f.Set("off")
    47  }
    48  
    49  func (f Feature) FlagsOn() specobj.SpecObj {
    50  	return f.EntrySpec(Key("set@" + f.Value()))
    51  }
    52  
    53  func (f Feature) PkgconfRequire() []string {
    54  	return f.EntryStrList(KeyPkgconfRequire)
    55  }