-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.go
88 lines (78 loc) · 2.27 KB
/
create.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
package main
import (
"fmt"
"log"
"os"
"os/exec"
"runtime"
"github.com/cli/go-gh/v2/pkg/repository"
"github.com/spf13/cobra"
)
func runCreate(cmd *cobra.Command, repo repository.Repository, remove bool, folderName string, URL string) (err error) {
orgOverride, _ := cmd.Flags().GetString("org")
entOverride, _ := cmd.Flags().GetString("enterprise")
labels, _ := cmd.Flags().GetString("labels")
replace, _ := cmd.Flags().GetBool("replace")
group, _ := cmd.Flags().GetString("group")
skipDownload, _ := cmd.Flags().GetBool("skip-download")
windowsService, _ := cmd.Flags().GetBool("windows-service")
windowsLogonAccount, _ := cmd.Flags().GetString("windowslogonaccont")
windowsLogonPassword, _ := cmd.Flags().GetString("windowslogonpassword")
var org string
var ent string
if orgOverride != "" {
org = orgOverride
URL = fmt.Sprintf("https://%s/%s", repo.Host, org)
}
if entOverride != "" {
ent = entOverride
URL = fmt.Sprintf("https://%s/enterprises/%s", repo.Host, ent)
}
if !remove && !skipDownload {
// Get the correct runner for the current platform
fileName, url := FindRunner()
Download(fileName, url)
ExtractToFolder(fileName, folderName)
}
err = os.Chdir(folderName)
if err != nil {
log.Fatal(err)
}
token := GetToken(repo, org, ent, remove)
var args []string
if remove {
args = []string{"remove", "--token", token}
} else {
args = []string{"--url", URL, "--token", token, "--name", folderName, "--unattended"}
if replace {
args = append(args, "--replace")
}
if labels != "" {
args = append(args, "--labels", labels)
}
if group != "" {
args = append(args, "--runnergroup", group)
}
}
configCmd := exec.Command("./config.sh", args...)
if runtime.GOOS == "windows" {
if windowsService {
args = append(args, "--runasservice")
if windowsLogonAccount != "" {
if windowsLogonPassword == "" {
log.Fatal("windowslogonpassword is required when using windowslogonaccount")
}
args = append(args, "--windowslogonaccount", windowsLogonAccount)
args = append(args, "--windowslogonpassword", windowsLogonPassword)
}
}
configCmd = exec.Command(".\\config.cmd", args...)
}
configCmd.Stdout = os.Stdout
configCmd.Stderr = os.Stderr
err = configCmd.Run()
if err != nil {
log.Fatal(err)
}
return err
}