style: use switch/case instead of if/else
This commit is contained in:
parent
b1883bad73
commit
b57c0d6336
2 changed files with 40 additions and 39 deletions
|
|
@ -94,9 +94,12 @@ func pullRepository(repoName string, repoDestination string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorCount = errorCount + 1
|
errorCount = errorCount + 1
|
||||||
pulledCount = pulledCount - 1
|
pulledCount = pulledCount - 1
|
||||||
if strings.Contains(string(pullOutput), "You have unstaged changes") {
|
|
||||||
|
switch {
|
||||||
|
case strings.Contains(string(pullOutput), "You have unstaged changes"):
|
||||||
pullErrorMsg = append(pullErrorMsg, repoDestination)
|
pullErrorMsg = append(pullErrorMsg, repoDestination)
|
||||||
} else {
|
|
||||||
|
default:
|
||||||
log.Printf("pull error: %v", err)
|
log.Printf("pull error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,61 +23,59 @@ func manageArguments() {
|
||||||
gitlabToken = *tokenFlag
|
gitlabToken = *tokenFlag
|
||||||
gitlabHost = *hostFlag
|
gitlabHost = *hostFlag
|
||||||
|
|
||||||
// use environment variable if set, otherwise use flag value
|
// manage gitlab api option
|
||||||
if envHost := os.Getenv("GITLAB_URL"); envHost != "" {
|
switch envToken := os.Getenv("GITLAB_API_TOKEN"); {
|
||||||
gitlabHost = envHost
|
case envToken != "":
|
||||||
}
|
|
||||||
|
|
||||||
if envToken := os.Getenv("GITLAB_API_TOKEN"); envToken != "" {
|
|
||||||
gitlabToken = envToken
|
gitlabToken = envToken
|
||||||
}
|
default:
|
||||||
|
|
||||||
if envRepoDest := os.Getenv("GOGITLABBER_DESTINATION"); envRepoDest != "" {
|
|
||||||
repoDestinationPre = envRepoDest
|
|
||||||
}
|
|
||||||
|
|
||||||
if envArchived := os.Getenv("GOGITLABBER_ARCHIVED"); envArchived != "" {
|
|
||||||
includeArchived = envArchived
|
|
||||||
}
|
|
||||||
|
|
||||||
// fail if no configuration found
|
|
||||||
if gitlabHost == "" {
|
|
||||||
fmt.Println("Fatal: No GitLab Host found.")
|
|
||||||
flag.PrintDefaults()
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if gitlabToken == "" {
|
|
||||||
fmt.Println("Fatal: No GitLab API Token found.")
|
fmt.Println("Fatal: No GitLab API Token found.")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if repoDestinationPre == "" {
|
// manage gitlab url option
|
||||||
|
switch envHost := os.Getenv("GITLAB_URL"); {
|
||||||
|
case envHost != "":
|
||||||
|
gitlabHost = envHost
|
||||||
|
default:
|
||||||
|
fmt.Println("Fatal: No GitLab Host found.")
|
||||||
|
flag.PrintDefaults()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// manage destination option
|
||||||
|
switch envRepoDest := os.Getenv("GOGITLABBER_DESTINATION"); {
|
||||||
|
case envRepoDest != "":
|
||||||
|
repoDestinationPre = envRepoDest
|
||||||
|
default:
|
||||||
fmt.Println("Fatal: No destination found.")
|
fmt.Println("Fatal: No destination found.")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// --archive options:
|
// add slash 🎩🎸 if not provided
|
||||||
// - any (fetch both)
|
switch {
|
||||||
// - exclusive (fetch archived exclusive)
|
case !strings.HasSuffix(repoDestinationPre, "/"):
|
||||||
// - excluded (fetch non-archived exclusive - default)
|
repoDestinationPre += "/"
|
||||||
if includeArchived == "" {
|
|
||||||
includeArchived = "excluded"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if includeArchived != "any" &&
|
// manage archived option
|
||||||
includeArchived != "exclusive" &&
|
switch envArchived := os.Getenv("GOGITLABBER_ARCHIVED"); {
|
||||||
includeArchived != "excluded" {
|
case envArchived == "":
|
||||||
|
includeArchived = "excluded"
|
||||||
|
|
||||||
|
case envArchived == "any":
|
||||||
|
includeArchived = envArchived
|
||||||
|
|
||||||
|
case envArchived == "exclusive":
|
||||||
|
includeArchived = envArchived
|
||||||
|
|
||||||
|
case envArchived == "excluded":
|
||||||
|
includeArchived = envArchived
|
||||||
|
|
||||||
|
default:
|
||||||
fmt.Println("Fatal: Wrong archive option found.")
|
fmt.Println("Fatal: Wrong archive option found.")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add slash 🎩🎸 if not provided
|
|
||||||
if !strings.HasSuffix(repoDestinationPre, "/") {
|
|
||||||
repoDestinationPre += "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue