github.com/saymoon/flop@v0.1.6-0.20201205092451-00912199cc96/option.go (about) 1 package flop 2 3 import "fmt" 4 5 // Options directly represent command line flags associated with GNU file operations. 6 type Options struct { 7 // AppendNameToPath will, when attempting to copy a file to an existing directory, automatically 8 // create the file with the same name in the destination directory. While CP uses this behavior 9 // by default it is an assumption better left to the client in a programmatic setting. 10 AppendNameToPath bool 11 // Atomic will copy contents to a temporary file in the destination's parent directory first, then 12 // rename the file to ensure the operation is atomic. 13 Atomic bool 14 // Backup makes a backup of each existing destination file. The backup suffix is '~'. Acceptable 15 // control values are: 16 // - "off" no backup will be made (default) 17 // - "simple" always make simple backups 18 // - "numbered" make numbered backups 19 // - "existing" numbered if numbered backups exist, simple otherwise 20 Backup string 21 // Link creates hard links to files instead of copying them. 22 Link bool 23 // MkdirAll will use os.MkdirAll to create the destination directory if it does not exist, along with 24 // any necessary parents. 25 MkdirAll bool 26 // mkdirAll is an internal tracker for MkdirAll, including other validation checks 27 mkdirAll bool 28 // NoClobber will not let an existing file be overwritten. 29 NoClobber bool 30 // Parents will create source directories in dst if they do not already exist. ErrWithParentsDstMustBeDir 31 // is returned if destination is not a directory. 32 Parents bool 33 // Recursive will recurse through sub directories if set true. 34 Recursive bool 35 // InfoLogFunc will, if defined, handle logging info messages. 36 InfoLogFunc func(string) 37 // DebugLogFunc will, if defined, handle logging debug messages. 38 DebugLogFunc func(string) 39 } 40 41 // setLoggers will configure logging functions, setting noop loggers if log funcs are undefined. 42 func (o *Options) setLoggers() { 43 if o.InfoLogFunc == nil { 44 o.InfoLogFunc = func(string) {} 45 } 46 if o.DebugLogFunc == nil { 47 o.DebugLogFunc = func(string) {} 48 } 49 } 50 51 // logDebug will log to the DebugLogFunc. 52 func (o *Options) logDebug(format string, a ...interface{}) { 53 o.DebugLogFunc(fmt.Sprintf(format, a...)) 54 } 55 56 // logInfo will log to the InfoLogFunc. 57 func (o *Options) logInfo(format string, a ...interface{}) { 58 o.InfoLogFunc(fmt.Sprintf(format, a...)) 59 }