-
Notifications
You must be signed in to change notification settings - Fork 1
/
command.go
96 lines (82 loc) · 2.01 KB
/
command.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"errors"
"fmt"
"os"
"os/exec"
)
type Command struct {
Base []string
Type string
}
func NewCommand(t string) *Command {
return &Command{
Base: []string{},
Type: t}
}
// Execute executes a command
func (command *Command) Execute() error {
if len(command.Base) < 2 {
return errors.New("command is too short")
}
cmd := exec.Command(command.Base[0], command.Base[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func (command *Command) Copy(bucket string, files []string, recursive bool) {
if command.Type == "gsutil" {
command.Base = append(command.Base, []string{
"gsutil",
"cp"}...)
if recursive {
command.Base = append(command.Base, "-R")
}
command.Base = append(command.Base, files...)
command.Base = append(command.Base, bucket)
}
if command.Type == "swift" {
command.Base = append(command.Base, []string{
"swift",
"upload"}...)
command.Base = append(command.Base, bucket)
command.Base = append(command.Base, files...)
}
}
func (command *Command) Public(bucket string, files []string) {
if command.Type == "gsutil" {
command.Base = append(command.Base, []string{
"gsutil",
"acl",
"set",
"public-read"}...)
for _, file := range files {
filePath := fmt.Sprintf("%s%s", bucket, file)
command.Base = append(command.Base, filePath)
}
}
if command.Type == "swift" {
command.Base = append(command.Base, []string{
"echo",
"-p flag not supported for swift platforms. Skipping."}...)
}
}
func (command *Command) DaisyChain(originPath, destPath string, recursive bool) {
if command.Type == "gsutil" {
command.Base = append(command.Base, []string{
"gsutil",
"cp",
"-D",
"-p"}...)
if recursive {
command.Base = append(command.Base, "-R")
}
command.Base = append(command.Base, originPath)
command.Base = append(command.Base, destPath)
}
if command.Type == "swift" {
command.Base = append(command.Base, []string{
"echo",
"-b flag not supported for swift platforms. Skipping."}...)
}
}