github.com/1800alex/go-git-cmd-wrapper/v2@v2.2.5/config/config_custom.go (about)

     1  package config
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"github.com/1800alex/go-git-cmd-wrapper/v2/types"
     7  )
     8  
     9  // Entry Adds a configuration entry.
    10  func Entry(key, value string) func(*types.Cmd) {
    11  	return func(g *types.Cmd) {
    12  		g.AddOptions(key)
    13  		g.AddOptions(value)
    14  	}
    15  }
    16  
    17  // Add Adds a new line to the option without altering any existing values. This is the same as providing ^$ as the value_regex in --replace-all.
    18  // --add
    19  func Add(name, value string) func(*types.Cmd) {
    20  	return func(g *types.Cmd) {
    21  		g.AddOptions("--add")
    22  		g.AddOptions(name)
    23  		g.AddOptions(value)
    24  	}
    25  }
    26  
    27  // ReplaceAll Default behavior is to replace at most one line. This replaces all lines matching the key (and optionally the value_regex).
    28  // --replace-all
    29  func ReplaceAll(name, value, valueRegex string) func(*types.Cmd) {
    30  	return func(g *types.Cmd) {
    31  		g.AddOptions("--replace-all")
    32  		g.AddOptions(name)
    33  		g.AddOptions(value)
    34  		if valueRegex != "" {
    35  			g.AddOptions(valueRegex)
    36  		}
    37  	}
    38  }
    39  
    40  // Get the value for a given key (optionally filtered by a regex matching the value). Returns error code 1 if the key was not found and the last value if multiple key values were found.
    41  // --get
    42  func Get(name, valueRegex string) func(*types.Cmd) {
    43  	return func(g *types.Cmd) {
    44  		g.AddOptions("--get")
    45  		g.AddOptions(name)
    46  		if valueRegex != "" {
    47  			g.AddOptions(valueRegex)
    48  		}
    49  	}
    50  }
    51  
    52  // GetAll Like get, but returns all values for a multi-valued key.
    53  // --get-all
    54  func GetAll(name, valueRegex string) func(*types.Cmd) {
    55  	return func(g *types.Cmd) {
    56  		g.AddOptions("--get-all")
    57  		g.AddOptions(name)
    58  		if valueRegex != "" {
    59  			g.AddOptions(valueRegex)
    60  		}
    61  	}
    62  }
    63  
    64  // GetRegexp Like --get-all, but interprets the name as a regular expression and writes out the key names. Regular expression matching is currently case-sensitive and done against a canonicalized version of the key in which section and variable names are lowercased, but subsection names are not.
    65  // --get-regexp
    66  func GetRegexp(nameRegexp, valueRegex string) func(*types.Cmd) {
    67  	return func(g *types.Cmd) {
    68  		g.AddOptions("--get-regexp")
    69  		g.AddOptions(nameRegexp)
    70  		if valueRegex != "" {
    71  			g.AddOptions(valueRegex)
    72  		}
    73  	}
    74  }
    75  
    76  // GetURLMatch When given a two-part name section.key, the value for section.<url>.key whose <url> part matches the best to the given URL is returned (if no such key exists, the value for section.key is used as a fallback). When given just the section as name, do so for all the keys in the section and list them. Returns error code 1 if no value is found.
    77  // --get-urlmatch name URL
    78  func GetURLMatch(name, url string) func(*types.Cmd) {
    79  	return func(g *types.Cmd) {
    80  		g.AddOptions("--get-urlmatch")
    81  		g.AddOptions(name)
    82  		g.AddOptions(url)
    83  	}
    84  }
    85  
    86  // Unset Remove the line matching the key from config file.
    87  // --unset
    88  func Unset(name, valueRegex string) func(*types.Cmd) {
    89  	return func(g *types.Cmd) {
    90  		g.AddOptions("--unset")
    91  		g.AddOptions(name)
    92  		if valueRegex != "" {
    93  			g.AddOptions(valueRegex)
    94  		}
    95  	}
    96  }
    97  
    98  // UnsetAll Remove all lines matching the key from config file.
    99  // --unset-all
   100  func UnsetAll(name, valueRegex string) func(*types.Cmd) {
   101  	return func(g *types.Cmd) {
   102  		g.AddOptions("--unset-all")
   103  		g.AddOptions(name)
   104  		if valueRegex != "" {
   105  			g.AddOptions(valueRegex)
   106  		}
   107  	}
   108  }
   109  
   110  // RenameSection Rename the given section to a new name.
   111  // --rename-section
   112  func RenameSection(oldName, newName string) func(*types.Cmd) {
   113  	return func(g *types.Cmd) {
   114  		g.AddOptions("--rename-section")
   115  		g.AddOptions(oldName)
   116  		g.AddOptions(newName)
   117  	}
   118  }
   119  
   120  // RemoveSection Remove the given section from the configuration file.
   121  // --remove-section
   122  func RemoveSection(name string) func(*types.Cmd) {
   123  	return func(g *types.Cmd) {
   124  		g.AddOptions("--remove-section")
   125  		g.AddOptions(name)
   126  	}
   127  }
   128  
   129  // GetColor Find the color configured for name (e.g.  color.diff.new) and output it as the ANSI color escape sequence to the standard output. The optional default parameter is used instead, if there is no color configured for name.
   130  // --get-color name [default]
   131  func GetColor(name, defaultValue string) func(*types.Cmd) {
   132  	return func(g *types.Cmd) {
   133  		g.AddOptions("--get-color")
   134  		g.AddOptions(name)
   135  		if defaultValue != "" {
   136  			g.AddOptions(defaultValue)
   137  		}
   138  	}
   139  }
   140  
   141  // GetColorBool Find the color setting for name (e.g.  color.diff) and output "true" or "false".  stdout-is-tty should be either "true" or "false", and is taken into account when configuration says "auto". If stdout-is-tty is missing, then checks the standard output of the command itself, and exits with status 0 if color is to be used, or exits with status 1 otherwise. When the color setting for name is undefined, the command uses color.ui as fallback.
   142  // --get-colorbool name [stdout-is-tty]
   143  func GetColorBool(name string, stdoutIsTTY bool) func(*types.Cmd) {
   144  	return func(g *types.Cmd) {
   145  		g.AddOptions("--get-colorbool")
   146  		g.AddOptions(name)
   147  		g.AddOptions(strconv.FormatBool(stdoutIsTTY))
   148  	}
   149  }
   150  
   151  // --[no-]includes
   152  // Respect include.*  directives in config files when looking up values. Defaults to off when a specific file is given (e.g., using --file, --global, etc) and on when searching all config files.