github.com/cli/cli@v1.14.1-0.20210902173923-1af6a669e342/internal/config/stub.go (about)

     1  package config
     2  
     3  import (
     4  	"errors"
     5  )
     6  
     7  type ConfigStub map[string]string
     8  
     9  func genKey(host, key string) string {
    10  	if host != "" {
    11  		return host + ":" + key
    12  	}
    13  	return key
    14  }
    15  
    16  func (c ConfigStub) Get(host, key string) (string, error) {
    17  	val, _, err := c.GetWithSource(host, key)
    18  	return val, err
    19  }
    20  
    21  func (c ConfigStub) GetWithSource(host, key string) (string, string, error) {
    22  	if v, found := c[genKey(host, key)]; found {
    23  		return v, "(memory)", nil
    24  	}
    25  	return "", "", errors.New("not found")
    26  }
    27  
    28  func (c ConfigStub) Set(host, key, value string) error {
    29  	c[genKey(host, key)] = value
    30  	return nil
    31  }
    32  
    33  func (c ConfigStub) Aliases() (*AliasConfig, error) {
    34  	return nil, nil
    35  }
    36  
    37  func (c ConfigStub) Hosts() ([]string, error) {
    38  	return nil, nil
    39  }
    40  
    41  func (c ConfigStub) UnsetHost(hostname string) {
    42  }
    43  
    44  func (c ConfigStub) CheckWriteable(host, key string) error {
    45  	return nil
    46  }
    47  
    48  func (c ConfigStub) Write() error {
    49  	c["_written"] = "true"
    50  	return nil
    51  }
    52  
    53  func (c ConfigStub) DefaultHost() (string, error) {
    54  	return "", nil
    55  }
    56  
    57  func (c ConfigStub) DefaultHostWithSource() (string, string, error) {
    58  	return "", "", nil
    59  }