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
|
||||
mu.Lock()
|
||||
clonedCount++
|
||||
if !verbose {
|
||||
if !debug {
|
||||
// update the progress bar
|
||||
descriptionPrefixPre := "Cloning repository "
|
||||
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
||||
|
|
@ -89,7 +89,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
case strings.Contains(string(repoStatus), url):
|
||||
logPrint("Decided to pull repository: "+repoName, nil)
|
||||
pullRepository(repoName, repoDestination)
|
||||
if !verbose {
|
||||
if !debug {
|
||||
descriptionPrefixPre := "Pulling repository "
|
||||
descriptionPrefix := descriptionPrefixPre + repoName + " ..."
|
||||
bar.Describe(descriptionPrefix)
|
||||
|
|
@ -103,7 +103,7 @@ func checkoutRepositories(repositories []Repository, concurrency int) {
|
|||
// set a lock, increment counters and unlock
|
||||
mu.Lock()
|
||||
errorCount++
|
||||
if !verbose {
|
||||
if !debug {
|
||||
progressBarAdd(1)
|
||||
}
|
||||
mu.Unlock()
|
||||
|
|
|
|||
|
|
@ -27,16 +27,16 @@ func fetchRepositoriesGitlab() ([]Repository, error) {
|
|||
url := fmt.Sprintf("https://%s/api/v4/projects?%s&%s&%s%s",
|
||||
gitlabHost, membership, order, perpage, archived)
|
||||
|
||||
logPrint("Creating API request", nil)
|
||||
logPrint("HTTP: Creating API request", nil)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
logPrint("Making request", nil)
|
||||
logPrint("HTTP: Making request", nil)
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
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)
|
||||
}
|
||||
|
||||
logPrint("Decoding JSON response", nil)
|
||||
logPrint("HTTP: Decoding JSON response", nil)
|
||||
var repositories []Repository
|
||||
if err := json.NewDecoder(resp.Body).Decode(&repositories); err != nil {
|
||||
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")
|
||||
}
|
||||
|
||||
logPrint("Returning repositories found", nil)
|
||||
logPrint("HTTP: Returning repositories found", 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 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 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()
|
||||
|
||||
|
|
@ -26,50 +26,49 @@ func manageArguments() {
|
|||
gitlabToken = *tokenFlag
|
||||
includeArchived = *archivedFlag
|
||||
repoDestinationPre = *destinationFlag
|
||||
verbose = *verboseFlag
|
||||
debug = *debugFlag
|
||||
|
||||
// manage verbosity option
|
||||
switch envVerbose := os.Getenv("GOGITLABBER_VERBOSE"); {
|
||||
case envVerbose != "":
|
||||
// manage verosity option
|
||||
switch envDebug := os.Getenv("GOGITLABBER_DEBUG"); {
|
||||
case envDebug != "":
|
||||
var err error
|
||||
verbose, err = strconv.ParseBool(envVerbose)
|
||||
logPrint("CONFIG: verbose option found", nil)
|
||||
debug, err = strconv.ParseBool(envDebug)
|
||||
logPrint("Configuration: debug option found", nil)
|
||||
if err != nil {
|
||||
logFatal("FATAL: config; not a valid bool", nil)
|
||||
}
|
||||
default:
|
||||
flag.Usage()
|
||||
logFatal("FATAL: config; no verbose option found", nil)
|
||||
debug = false
|
||||
}
|
||||
|
||||
// manage gitlab api option
|
||||
switch envToken := os.Getenv("GITLAB_API_TOKEN"); {
|
||||
case envToken != "":
|
||||
gitlabToken = envToken
|
||||
logPrint("CONFIG: Gitlab API Token found", nil)
|
||||
logPrint("Configuration: Gitlab API Token found", nil)
|
||||
default:
|
||||
flag.Usage()
|
||||
logFatal("CONFIG: Giltab API Token not found", nil)
|
||||
logFatal("Configuration: Giltab API Token not found", nil)
|
||||
}
|
||||
|
||||
// manage gitlab url option
|
||||
switch envHost := os.Getenv("GITLAB_URL"); {
|
||||
case envHost != "":
|
||||
gitlabHost = envHost
|
||||
logPrint("CONFIG: Gitlab host found", nil)
|
||||
logPrint("Configuration: Gitlab host found", nil)
|
||||
default:
|
||||
flag.Usage()
|
||||
logFatal("CONFIG: Gitlab host not found", nil)
|
||||
logFatal("Configuration: Gitlab host not found", nil)
|
||||
}
|
||||
|
||||
// manage destination option
|
||||
switch envRepoDest := os.Getenv("GOGITLABBER_DESTINATION"); {
|
||||
case envRepoDest != "":
|
||||
repoDestinationPre = envRepoDest
|
||||
logPrint("CONFIG: destination found", nil)
|
||||
logPrint("Configuration: destination found", nil)
|
||||
default:
|
||||
flag.Usage()
|
||||
logFatal("CONFIG: destination not found", nil)
|
||||
logFatal("Configuration: destination not found", nil)
|
||||
}
|
||||
|
||||
// add slash 🎩🎸 if not provided
|
||||
|
|
@ -85,10 +84,10 @@ func manageArguments() {
|
|||
case envConcurrency != "":
|
||||
concurrencyValue, err := strconv.Atoi(envConcurrency)
|
||||
if err != nil {
|
||||
logFatal("invalid concurrency value in environment: %v", err)
|
||||
logFatal("invalid concurrency value found in environment: %v", err)
|
||||
}
|
||||
concurrency = concurrencyValue
|
||||
logPrint("CONFIG: concurrency option found", nil)
|
||||
logPrint("Configuration: concurrency option found", nil)
|
||||
default:
|
||||
flag.Usage()
|
||||
log.Fatalln("FATAL: config; concurrency not found")
|
||||
|
|
@ -98,22 +97,22 @@ func manageArguments() {
|
|||
switch envArchived := os.Getenv("GOGITLABBER_ARCHIVED"); {
|
||||
case envArchived == "":
|
||||
includeArchived = "excluded"
|
||||
logPrint("CONFIG: archive option found", nil)
|
||||
logPrint("Configuration: archive option found", nil)
|
||||
|
||||
case envArchived == "any":
|
||||
includeArchived = envArchived
|
||||
logPrint("CONFIG: archive option found", nil)
|
||||
logPrint("Configuration: archive option found", nil)
|
||||
|
||||
case envArchived == "exclusive":
|
||||
includeArchived = envArchived
|
||||
logPrint("CONFIG: archive option found", nil)
|
||||
logPrint("Configuration: archive option found", nil)
|
||||
|
||||
case envArchived == "excluded":
|
||||
includeArchived = envArchived
|
||||
logPrint("CONFIG: archive option found", nil)
|
||||
logPrint("Configuration: archive option found", nil)
|
||||
|
||||
default:
|
||||
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 includeArchived string
|
||||
var repoDestinationPre string
|
||||
var verbose bool
|
||||
var debug bool
|
||||
|
||||
// keep count 🧛
|
||||
var clonedCount int
|
||||
|
|
@ -43,8 +43,8 @@ func main() {
|
|||
logFatal("FATAL: %v", err)
|
||||
}
|
||||
|
||||
// print progressbar ony if not in verbose mode
|
||||
if !verbose {
|
||||
// print progressbar ony if not in debug mode
|
||||
if !debug {
|
||||
progressBar(repositories)
|
||||
log.SetOutput(io.Discard)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,12 +68,12 @@ func printPullError(pullErrorMsg []string) {
|
|||
}
|
||||
|
||||
func logPrint(message string, err error) {
|
||||
if verbose {
|
||||
if debug {
|
||||
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 {
|
||||
log.Printf("gogitlabber | %v\n", message)
|
||||
log.Printf("gogitlabber | DEBUG: %v\n", message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue