github.com/jacekolszak/noteo@v0.5.0/config/config.go (about)

     1  // Package config provides configuration from merging environment and repository config
     2  package config
     3  
     4  import (
     5  	"os"
     6  	"runtime"
     7  )
     8  
     9  type RepoConfig interface {
    10  	EditorCommand() string
    11  }
    12  
    13  type Config struct {
    14  	repoConfig RepoConfig
    15  }
    16  
    17  func New(config RepoConfig) *Config {
    18  	return &Config{repoConfig: config}
    19  }
    20  
    21  func (c *Config) EditorCommand() string {
    22  	if c.repoConfig.EditorCommand() != "" {
    23  		return c.repoConfig.EditorCommand()
    24  	}
    25  	if visual := os.Getenv("VISUAL"); visual != "" {
    26  		return visual
    27  	}
    28  	if editor := os.Getenv("EDITOR"); editor != "" {
    29  		return editor
    30  	}
    31  	if runtime.GOOS == "windows" {
    32  		return "notepad"
    33  	}
    34  	return "vim +"
    35  }