github.com/lgug2z/story@v0.4.1/git/clone.go (about) 1 package git 2 3 import ( 4 "fmt" 5 "os/exec" 6 "strings" 7 ) 8 9 type CloneOpts struct { 10 Repository string 11 Directory string 12 } 13 14 func Clone(opts CloneOpts) (string, error) { 15 var args []string 16 args = append(args, "clone", opts.Repository) 17 18 command := exec.Command("git", args...) 19 if opts.Directory != "" { 20 command.Args = append(command.Args, opts.Directory) 21 } 22 23 combinedOutput, err := command.CombinedOutput() 24 if err != nil { 25 return "", fmt.Errorf("%s: %s", err, combinedOutput) 26 } 27 28 return strings.TrimSpace(string(combinedOutput)), nil 29 }