-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprocessor.go
More file actions
46 lines (37 loc) · 1.21 KB
/
Copy pathprocessor.go
File metadata and controls
46 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"io"
"os"
"os/exec"
)
type TemplateProcessor interface {
Process(src, dest string, config Config, output io.Writer) error
}
type GitTemplateProcessor struct {
Branch string
}
func (p *GitTemplateProcessor) Process(src, dest string, config Config, output io.Writer) error {
if src != config.TemplateSrc {
return fmt.Errorf("source path '%s' does not match config template source '%s'", src, config.TemplateSrc)
}
logProgress(output, fmt.Sprintf("Cloning Git repository from '%s'...", src))
args := []string{"clone"}
if p.Branch != "" {
args = append(args, "--branch", p.Branch)
logProgress(output, fmt.Sprintf("Using branch '%s'...", p.Branch))
}
args = append(args, src, dest)
cmd := exec.Command("git", args...)
cmd.Stdout = output
cmd.Stderr = os.Stderr
return cmd.Run()
}
type LocalTemplateProcessor struct{}
func (p *LocalTemplateProcessor) Process(src, dest string, config Config, output io.Writer) error {
if src != config.TemplateSrc {
return fmt.Errorf("source path '%s' does not match config template source '%s'", src, config.TemplateSrc)
}
logProgress(output, fmt.Sprintf("Copying local template from '%s'...", src))
return copyDir(src, dest, config, output)
}