github.com/wtfutil/wtf@v0.43.0/modules/git/settings.go (about)

     1  package git
     2  
     3  import (
     4  	"github.com/olebedev/config"
     5  	"github.com/wtfutil/wtf/cfg"
     6  	"github.com/wtfutil/wtf/utils"
     7  )
     8  
     9  const (
    10  	defaultFocusable = true
    11  	defaultTitle     = "Git"
    12  )
    13  
    14  type Settings struct {
    15  	*cfg.Common
    16  
    17  	commitCount      int           `help:"The number of past commits to display." values:"A positive integer, 0..n." optional:"true"`
    18  	sections         []interface{} `help:"Sections to show" optional:"true"`
    19  	showModuleName   bool          `help:"Whether to show 'Git - ' before information in title" optional:"true" default:"true"`
    20  	branchInTitle    bool          `help:"Whether to show branch name in title instead of the widget body itself" optional:"true" default:"false"`
    21  	showFilesIfEmpty bool          `help:"Whether to show Changed Files section if no changed files" optional:"true" default:"true"`
    22  	lastFolderTitle  bool          `help:"Whether to show only last part of directory path instead of full path" optional:"true" default:"false"`
    23  	commitFormat     string        `help:"The string format for the commit message." optional:"true"`
    24  	dateFormat       string        `help:"The string format for the date/time in the commit message." optional:"true"`
    25  	repositories     []interface{} `help:"Defines which git repositories to watch." values:"A list of zero or more local file paths pointing to valid git repositories."`
    26  }
    27  
    28  func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
    29  	settings := Settings{
    30  		Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
    31  
    32  		commitCount:      ymlConfig.UInt("commitCount", 10),
    33  		sections:         ymlConfig.UList("sections"),
    34  		showModuleName:   ymlConfig.UBool("showModuleName", true),
    35  		branchInTitle:    ymlConfig.UBool("branchInTitle", false),
    36  		showFilesIfEmpty: ymlConfig.UBool("showFilesIfEmpty", true),
    37  		lastFolderTitle:  ymlConfig.UBool("lastFolderTitle", false),
    38  		commitFormat:     ymlConfig.UString("commitFormat", "[forestgreen]%h [white]%s [grey]%an on %cd[white]"),
    39  		dateFormat:       ymlConfig.UString("dateFormat", "%b %d, %Y"),
    40  		repositories:     ymlConfig.UList("repositories"),
    41  	}
    42  	if len(settings.sections) == 0 {
    43  		for _, v := range []string{"branch", "files", "commits"} {
    44  			settings.sections = append(settings.sections, v)
    45  		}
    46  	}
    47  
    48  	return &settings
    49  }
    50  
    51  func (widget *Widget) ConfigText() string {
    52  	return utils.HelpFromInterface(Settings{})
    53  }