Documentation ¶
Index ¶
- Variables
- func CopyFile(dst string, src string) error
- func ExecInTTY(name string, arg ...string) error
- func IsEmptyFile(path string) (bool, error)
- func SamePath(path1, path2 string) (bool, error)
- func TmplFuncMap(t *template.Template) template.FuncMap
- type GoTemplate
- type GoTemplateFS
- type KV
- type Logswitcher
Constants ¶
This section is empty.
Variables ¶
var ( // FilepathFuncMap provides standard functions to build/manipulate path in // template.Funcmap's format: // - base : get the path basename // - ext : get file extension // - sep : return a path separator ('\' of '/') // - sanitizePath : replace special chars that don't usually work well when // use in path name // - sanitizeFilename: like sanitizePath but also // removes any path separators. // - nospace : get rid of spaces FilepathFuncMap = template.FuncMap{ "base": filepath.Base, "ext": filepath.Ext, "sep": func() string { return string(filepath.Separator) }, "sanitizePath": pathSanitizer, "sanitizeFilename": filenameSanitizer, "nospace": nospaceSanitizer, } // StringsFuncMap provides standard functions to manipulate strings in // template.Funcmap's format: // - join : join elements separating them wit the given separator. // - lower: convert string to lower-case // - title: convert string to title-case // - upper: convert string to upper-case StringsFuncMap = template.FuncMap{ "join": strings.Join, "lower": strings.ToLower, "title": strings.ToTitle, "upper": strings.ToUpper, } // SerializationFuncMap provides standard functions to serialize/deserialize an // interface in template.Funcmap's format: // - toJSON : converts an interface to JSON representation. // - toPrettyJSON: converts an interface to an easy-to-read JSON representation. SerializationFuncMap = template.FuncMap{ "toJSON": func(v interface{}) (string, error) { output, err := json.Marshal(v) if err != nil { return "", err } return string(output), nil }, "toPrettyJSON": func(v interface{}) (string, error) { output, err := json.MarshalIndent(v, "", " ") if err != nil { return "", err } return string(output), nil }, } )
var ( // ErrUnknownLogStatus is returned when trying to set a logswitcher's // status tat is neither 'true' nor 'false'. ErrUnknownLogStatus = errors.New("unknown status") )
Functions ¶
func CopyFile ¶
CopyFile copies src to dst. Directories hosting dst are created as needed. if dst exists, copy does not happen and an error is returned. copyFile forces write to disk (Sync() method of os.File), and value certainty that write operation happens correctly over performance.
func IsEmptyFile ¶ added in v0.3.0
IsEmptyFile checks whether a file is empty or not.
func SamePath ¶
SamePath checks if two path strings are representing the same path. Limitation: this version is only comparing the path strings and do not consider situations where path string are different but are pointing to the same location on file-system.
func TmplFuncMap ¶
TmplFuncMap provides standard functions to execute go text templates path in template.Funcmap's format:
- tmpl : execute a sub-template by name. Sub-templates are chosen from t namespace. Unlike {{template xXx}}, tmpl allows to pipe its result to another command.
Types ¶
type GoTemplate ¶
GoTemplate wraps a text/template.Template to implement flag.Value interface and get customization through command-line.
func NewGoTemplate ¶
func NewGoTemplate(tmpl *template.Template) *GoTemplate
NewGoTemplate creates a new GoTemplate.
func (*GoTemplate) Set ¶
func (gotmpl *GoTemplate) Set(tmpl string) error
Set implements flag.Value interface for a GoTemplate.
func (GoTemplate) String ¶
func (gotmpl GoTemplate) String() string
String proposes a human-friendly string representation of a go template.
type GoTemplateFS ¶
GoTemplateFS wraps a text/template.Template that parses its template definition from files in order to implement flag.Value interface and get customization through command-line.
func NewGoTemplateFS ¶
func NewGoTemplateFS(tmpl *template.Template) *GoTemplateFS
NewGoTemplateFS creates a new GoTemplateFS.
func (*GoTemplateFS) Set ¶
func (gotmplFS *GoTemplateFS) Set(pattern string) error
Set implements flag.Value interface for a GoTemplateFS.
func (GoTemplateFS) String ¶
func (gotmplFS GoTemplateFS) String() string
String proposes a human-friendly string representation of a go template.
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
KV wraps a map to implement flag.Value interface and get ability to allow user to define (key, value) through command-line.
type Logswitcher ¶
type Logswitcher struct {
// contains filtered or unexported fields
}
Logswitcher wraps a set of log.Logger to implement flag.Value interface and get activation/de-activation from command-line. When activated, logger will print to os.Stderr.
func NewLogSwitcher ¶
func NewLogSwitcher(loggers ...*log.Logger) *Logswitcher
NewLogSwitcher creates a new Logger that prints nothing (output is io.Discard), waiting for user to trigger it through command-line flags.
func (Logswitcher) IsBoolFlag ¶
func (ls Logswitcher) IsBoolFlag() bool
IsBoolFlag implements flag.Value interface to notify that logswitcher flag is boolean.
func (*Logswitcher) Set ¶
func (ls *Logswitcher) Set(status string) error
Set implements flag.Value interface to set logswitcher's status from command-line. Status could be either true or false.
func (Logswitcher) String ¶
func (ls Logswitcher) String() string
String proposes a human-friendly string representation of a logswitcher.