github.com/getong/docker@v1.13.1/integration-cli/utils.go (about) 1 package main 2 3 import ( 4 "io" 5 "os" 6 "os/exec" 7 "time" 8 9 "github.com/docker/docker/pkg/integration" 10 "github.com/docker/docker/pkg/integration/cmd" 11 ) 12 13 func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) { 14 if daemonPlatform == "windows" { 15 return "c:", `\` 16 } 17 return "", "/" 18 } 19 20 // TODO: update code to call cmd.RunCmd directly, and remove this function 21 func runCommandWithOutput(execCmd *exec.Cmd) (string, int, error) { 22 result := cmd.RunCmd(transformCmd(execCmd)) 23 return result.Combined(), result.ExitCode, result.Error 24 } 25 26 // TODO: update code to call cmd.RunCmd directly, and remove this function 27 func runCommandWithStdoutStderr(execCmd *exec.Cmd) (string, string, int, error) { 28 result := cmd.RunCmd(transformCmd(execCmd)) 29 return result.Stdout(), result.Stderr(), result.ExitCode, result.Error 30 } 31 32 // TODO: update code to call cmd.RunCmd directly, and remove this function 33 func runCommand(execCmd *exec.Cmd) (exitCode int, err error) { 34 result := cmd.RunCmd(transformCmd(execCmd)) 35 return result.ExitCode, result.Error 36 } 37 38 // Temporary shim for migrating commands to the new function 39 func transformCmd(execCmd *exec.Cmd) cmd.Cmd { 40 return cmd.Cmd{ 41 Command: execCmd.Args, 42 Env: execCmd.Env, 43 Dir: execCmd.Dir, 44 Stdin: execCmd.Stdin, 45 Stdout: execCmd.Stdout, 46 } 47 } 48 49 func runCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode int, err error) { 50 return integration.RunCommandPipelineWithOutput(cmds...) 51 } 52 53 func convertSliceOfStringsToMap(input []string) map[string]struct{} { 54 return integration.ConvertSliceOfStringsToMap(input) 55 } 56 57 func compareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error { 58 return integration.CompareDirectoryEntries(e1, e2) 59 } 60 61 func listTar(f io.Reader) ([]string, error) { 62 return integration.ListTar(f) 63 } 64 65 func randomTmpDirPath(s string, platform string) string { 66 return integration.RandomTmpDirPath(s, platform) 67 } 68 69 func consumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) { 70 return integration.ConsumeWithSpeed(reader, chunkSize, interval, stop) 71 } 72 73 func parseCgroupPaths(procCgroupData string) map[string]string { 74 return integration.ParseCgroupPaths(procCgroupData) 75 } 76 77 func runAtDifferentDate(date time.Time, block func()) { 78 integration.RunAtDifferentDate(date, block) 79 }