Skip to content

Commit

Permalink
Version 0.1.2, closes #1, #2
Browse files Browse the repository at this point in the history
  • Loading branch information
rednafi committed Mar 5, 2024
1 parent 3cd2e90 commit 4d3eb94
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (
)

const (
exitOk = 0
exitErr = 1
exitOk = 0
exitErr = 1
userNotFoundErr = "API request failed with status: 404"
invalidTokenErr = "API request failed with status: 401"
tokenPermissionErr = "API request failed with status: 403"
)

type repo struct {
Expand Down Expand Up @@ -294,7 +297,14 @@ func (c *cliConfig) CLI(args []string) int {
olderThanDays)

if err != nil {
fmt.Fprintf(stderr, "\nError fetching repositories: %v\n", err)
switch err.Error() {
case userNotFoundErr:
fmt.Fprintf(stderr, "Error: user not found\n")
case invalidTokenErr:
fmt.Fprintf(stderr, "Error: invalid token\n")
default:
fmt.Fprintf(stderr, "Error: %s\n", err)
}
return exitErr
}

Expand All @@ -316,7 +326,12 @@ func (c *cliConfig) CLI(args []string) int {

fmt.Fprintf(stdout, "\nDeleting forked repositories...\n")
if err := deleteRepos(ctx, baseURL, token, forkedRepos); err != nil {
fmt.Fprintf(stderr, "Error deleting repositories: %v \n", err)
switch err.Error() {
case tokenPermissionErr:
fmt.Fprintf(stderr, "Error: token does not have permission to delete repos\n")
default:
fmt.Fprintf(stderr, "Error: %s\n", err)
}
return exitErr
}

Expand Down

0 comments on commit 4d3eb94

Please sign in to comment.