forked from jfrog/artifactory-cli-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
93 lines (81 loc) · 1.53 KB
/
utils.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
package utils
import (
"os"
"fmt"
"strings"
"os/user"
"strconv"
"runtime"
)
var ExitCodeError ExitCode = ExitCode{1}
var ExitCodeWarning ExitCode = ExitCode{2}
type ExitCode struct {
Code int
}
func GetVersion() string {
return "1.3.0"
}
func CheckError(err error) {
if err != nil {
panic(err)
}
}
func Exit(exitCode ExitCode, msg string) {
if msg != "" {
fmt.Println(msg)
}
os.Exit(exitCode.Code)
}
func GetLogMsgPrefix(threadId int, dryRun bool) string {
var strDryRun string
if dryRun {
strDryRun = " [Dry run]"
} else {
strDryRun = ""
}
return "[Thread " + strconv.Itoa(threadId) + "]" + strDryRun
}
func GetFileSeperator() string {
if runtime.GOOS == "windows" {
return "\\"
}
return "/"
}
func GetHomeDir() string {
user, err := user.Current()
if err == nil {
return user.HomeDir
}
home := os.Getenv("HOME")
if home != "" {
return home
}
return "";
}
func AddTrailingSlashIfNeeded(url string) string {
if url != "" && !strings.HasSuffix(url, "/") {
url += "/"
}
return url
}
type Flags struct {
ArtDetails *ArtifactoryDetails
DryRun bool
Props string
Deb string
Recursive bool
Flat bool
UseRegExp bool
Threads int
MinSplitSize int64
SplitCount int
Interactive bool
EncPassword bool
}
type ArtifactoryDetails struct {
Url string
User string
Password string
SshKeyPath string
SshAuthHeaders map[string]string
}