feat: renamed verbose to debug and improved the messages
This commit is contained in:
parent
5207524381
commit
7b5cb295ff
5 changed files with 35 additions and 36 deletions
|
|
@ -76,7 +76,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
||||||
// set a lock, increment counters, update progressbar and unlock
|
// set a lock, increment counters, update progressbar and unlock
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
clonedCount++
|
clonedCount++
|
||||||
if !verbose {
|
if !debug {
|
||||||
// update the progress bar
|
// update the progress bar
|
||||||
descriptionPrefixPre := "Cloning repository "
|
descriptionPrefixPre := "Cloning repository "
|
||||||
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
||||||
|
|
@ -89,7 +89,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
||||||
case strings.Contains(string(repoStatus), url):
|
case strings.Contains(string(repoStatus), url):
|
||||||
logPrint("Decided to pull repository: "+repoName, nil)
|
logPrint("Decided to pull repository: "+repoName, nil)
|
||||||
pullRepository(repoName, repoDestination)
|
pullRepository(repoName, repoDestination)
|
||||||
if !verbose {
|
if !debug {
|
||||||
descriptionPrefixPre := "Pulling repository "
|
descriptionPrefixPre := "Pulling repository "
|
||||||
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
||||||
bar.Describe(descriptionPrefix)
|
bar.Describe(descriptionPrefix)
|
||||||
|
|
@ -103,7 +103,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
||||||
// set a lock, increment counters and unlock
|
// set a lock, increment counters and unlock
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
errorCount++
|
errorCount++
|
||||||
if !verbose {
|
if !debug {
|
||||||
progressBarAdd(1)
|
progressBarAdd(1)
|
||||||
}
|
}
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
|
|
||||||
|
|
@ -27,16 +27,16 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
|
||||||
url := fmt.Sprintf("https://%s/api/v4/projects?%s&%s&%s%s",
|
url := fmt.Sprintf("https://%s/api/v4/projects?%s&%s&%s%s",
|
||||||
gitlabHost, membership, order, perpage, archived)
|
gitlabHost, membership, order, perpage, archived)
|
||||||
|
|
||||||
logPrint("Creating API request", nil)
|
logPrint("HTTP: Creating API request", nil)
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("ERROR: creating request: %v\n", err)
|
return nil, fmt.Errorf("ERROR: creating request: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logPrint("Adding PRIVATE-TOKEN header to API request", nil)
|
logPrint("HTTP: Adding PRIVATE-TOKEN header to API request", nil)
|
||||||
req.Header.Set("PRIVATE-TOKEN", gitlabToken)
|
req.Header.Set("PRIVATE-TOKEN", gitlabToken)
|
||||||
|
|
||||||
logPrint("Making request", nil)
|
logPrint("HTTP: Making request", nil)
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -48,7 +48,7 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
|
||||||
return nil, fmt.Errorf("ERROR: API request failed with status: %d\n", resp.StatusCode)
|
return nil, fmt.Errorf("ERROR: API request failed with status: %d\n", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
logPrint("Decoding JSON response", nil)
|
logPrint("HTTP: Decoding JSON response", nil)
|
||||||
var repositories []Repository
|
var repositories []Repository
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&repositories); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&repositories); err != nil {
|
||||||
return nil, fmt.Errorf("ERROR: decoding response: %v\n", err)
|
return nil, fmt.Errorf("ERROR: decoding response: %v\n", err)
|
||||||
|
|
@ -58,6 +58,6 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
|
||||||
return repositories, fmt.Errorf("ERROR: no repositories found\n")
|
return repositories, fmt.Errorf("ERROR: no repositories found\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
logPrint("Returning repositories found", nil)
|
logPrint("HTTP: Returning repositories found", nil)
|
||||||
return repositories, nil
|
return repositories, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ func manageArguments() {
|
||||||
var destinationFlag = flag.String("destination", "$HOME/Documents", "Specify where to check the repositories out\n example: -destination=$HOME/repos\nenv = GOGITLABBER_DESTINATION\n")
|
var destinationFlag = flag.String("destination", "$HOME/Documents", "Specify where to check the repositories out\n example: -destination=$HOME/repos\nenv = GOGITLABBER_DESTINATION\n")
|
||||||
var hostFlag = flag.String("gitlab-url", "gitlab.com", "Specify GitLab host\n example: -gitlab-url=gitlab.com\nenv = GITLAB_URL\n")
|
var hostFlag = flag.String("gitlab-url", "gitlab.com", "Specify GitLab host\n example: -gitlab-url=gitlab.com\nenv = GITLAB_URL\n")
|
||||||
var tokenFlag = flag.String("gitlab-api-token", "", "Specify GitLab API token\n example: -gitlab-api=glpat-xxxx\nenv = GITLAB_API_TOKEN\n")
|
var tokenFlag = flag.String("gitlab-api-token", "", "Specify GitLab API token\n example: -gitlab-api=glpat-xxxx\nenv = GITLAB_API_TOKEN\n")
|
||||||
var verboseFlag = flag.Bool("verbose", false, "Specify verbosity\n example: -verbose=true\nenv = GOGITLABBER_VERBOSE\n")
|
var debugFlag = flag.Bool("debug", false, "Toggle debug mode\n example: -debug=true\nenv = GOGITLABBER_DEBUG\n")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
|
@ -26,50 +26,49 @@ func manageArguments() {
|
||||||
gitlabToken = *tokenFlag
|
gitlabToken = *tokenFlag
|
||||||
includeArchived = *archivedFlag
|
includeArchived = *archivedFlag
|
||||||
repoDestinationPre = *destinationFlag
|
repoDestinationPre = *destinationFlag
|
||||||
verbose = *verboseFlag
|
debug = *debugFlag
|
||||||
|
|
||||||
// manage verbosity option
|
// manage verosity option
|
||||||
switch envVerbose := os.Getenv("GOGITLABBER_VERBOSE"); {
|
switch envDebug := os.Getenv("GOGITLABBER_DEBUG"); {
|
||||||
case envVerbose != "":
|
case envDebug != "":
|
||||||
var err error
|
var err error
|
||||||
verbose, err = strconv.ParseBool(envVerbose)
|
debug, err = strconv.ParseBool(envDebug)
|
||||||
logPrint("CONFIG: verbose option found", nil)
|
logPrint("Configuration: debug option found", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logFatal("FATAL: config; not a valid bool", nil)
|
logFatal("FATAL: config; not a valid bool", nil)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
flag.Usage()
|
debug = false
|
||||||
logFatal("FATAL: config; no verbose option found", nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// manage gitlab api option
|
// manage gitlab api option
|
||||||
switch envToken := os.Getenv("GITLAB_API_TOKEN"); {
|
switch envToken := os.Getenv("GITLAB_API_TOKEN"); {
|
||||||
case envToken != "":
|
case envToken != "":
|
||||||
gitlabToken = envToken
|
gitlabToken = envToken
|
||||||
logPrint("CONFIG: Gitlab API Token found", nil)
|
logPrint("Configuration: Gitlab API Token found", nil)
|
||||||
default:
|
default:
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
logFatal("CONFIG: Giltab API Token not found", nil)
|
logFatal("Configuration: Giltab API Token not found", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// manage gitlab url option
|
// manage gitlab url option
|
||||||
switch envHost := os.Getenv("GITLAB_URL"); {
|
switch envHost := os.Getenv("GITLAB_URL"); {
|
||||||
case envHost != "":
|
case envHost != "":
|
||||||
gitlabHost = envHost
|
gitlabHost = envHost
|
||||||
logPrint("CONFIG: Gitlab host found", nil)
|
logPrint("Configuration: Gitlab host found", nil)
|
||||||
default:
|
default:
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
logFatal("CONFIG: Gitlab host not found", nil)
|
logFatal("Configuration: Gitlab host not found", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// manage destination option
|
// manage destination option
|
||||||
switch envRepoDest := os.Getenv("GOGITLABBER_DESTINATION"); {
|
switch envRepoDest := os.Getenv("GOGITLABBER_DESTINATION"); {
|
||||||
case envRepoDest != "":
|
case envRepoDest != "":
|
||||||
repoDestinationPre = envRepoDest
|
repoDestinationPre = envRepoDest
|
||||||
logPrint("CONFIG: destination found", nil)
|
logPrint("Configuration: destination found", nil)
|
||||||
default:
|
default:
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
logFatal("CONFIG: destination not found", nil)
|
logFatal("Configuration: destination not found", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add slash 🎩🎸 if not provided
|
// add slash 🎩🎸 if not provided
|
||||||
|
|
@ -85,10 +84,10 @@ func manageArguments() {
|
||||||
case envConcurrency != "":
|
case envConcurrency != "":
|
||||||
concurrencyValue, err := strconv.Atoi(envConcurrency)
|
concurrencyValue, err := strconv.Atoi(envConcurrency)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logFatal("invalid concurrency value in environment: %v", err)
|
logFatal("invalid concurrency value found in environment: %v", err)
|
||||||
}
|
}
|
||||||
concurrency = concurrencyValue
|
concurrency = concurrencyValue
|
||||||
logPrint("CONFIG: concurrency option found", nil)
|
logPrint("Configuration: concurrency option found", nil)
|
||||||
default:
|
default:
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
log.Fatalln("FATAL: config; concurrency not found")
|
log.Fatalln("FATAL: config; concurrency not found")
|
||||||
|
|
@ -98,22 +97,22 @@ func manageArguments() {
|
||||||
switch envArchived := os.Getenv("GOGITLABBER_ARCHIVED"); {
|
switch envArchived := os.Getenv("GOGITLABBER_ARCHIVED"); {
|
||||||
case envArchived == "":
|
case envArchived == "":
|
||||||
includeArchived = "excluded"
|
includeArchived = "excluded"
|
||||||
logPrint("CONFIG: archive option found", nil)
|
logPrint("Configuration: archive option found", nil)
|
||||||
|
|
||||||
case envArchived == "any":
|
case envArchived == "any":
|
||||||
includeArchived = envArchived
|
includeArchived = envArchived
|
||||||
logPrint("CONFIG: archive option found", nil)
|
logPrint("Configuration: archive option found", nil)
|
||||||
|
|
||||||
case envArchived == "exclusive":
|
case envArchived == "exclusive":
|
||||||
includeArchived = envArchived
|
includeArchived = envArchived
|
||||||
logPrint("CONFIG: archive option found", nil)
|
logPrint("Configuration: archive option found", nil)
|
||||||
|
|
||||||
case envArchived == "excluded":
|
case envArchived == "excluded":
|
||||||
includeArchived = envArchived
|
includeArchived = envArchived
|
||||||
logPrint("CONFIG: archive option found", nil)
|
logPrint("Configuration: archive option found", nil)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
logFatal("FATAL: config; no or wrong archive option found", nil)
|
logFatal("FATAL: Configuration: no or wrong archive option found", nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ var gitlabHost string
|
||||||
var gitlabToken string
|
var gitlabToken string
|
||||||
var includeArchived string
|
var includeArchived string
|
||||||
var repoDestinationPre string
|
var repoDestinationPre string
|
||||||
var verbose bool
|
var debug bool
|
||||||
|
|
||||||
// keep count 🧛
|
// keep count 🧛
|
||||||
var clonedCount int
|
var clonedCount int
|
||||||
|
|
@ -43,8 +43,8 @@ func main() {
|
||||||
logFatal("FATAL: %v", err)
|
logFatal("FATAL: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// print progressbar ony if not in verbose mode
|
// print progressbar ony if not in debug mode
|
||||||
if !verbose {
|
if !debug {
|
||||||
progressBar(repositories)
|
progressBar(repositories)
|
||||||
log.SetOutput(io.Discard)
|
log.SetOutput(io.Discard)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,12 +68,12 @@ func printPullError(pullErrorMsg []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func logPrint(message string, err error) {
|
func logPrint(message string, err error) {
|
||||||
if verbose {
|
if debug {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("gogitlabber | %v error: %v\n", message, err)
|
log.Printf("gogitlabber | DEBUG: %v error: %v\n", message, err)
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Printf("gogitlabber | %v\n", message)
|
log.Printf("gogitlabber | DEBUG: %v\n", message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue