Skip to content

Commit

Permalink
Tweak behavior of removal of non-existent repo
Browse files Browse the repository at this point in the history
Print message when repo doesn't exist (and return nil), instead of returning
an error. Only return error when client.Repositories.Delete fails. This
prevents `shorten remove ...` from dying early due to a repo not existing.
  • Loading branch information
kashav committed Mar 21, 2017
1 parent 9db296d commit 588448d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/remove.go
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"

"github.com/spf13/cobra"
Expand All @@ -10,7 +11,7 @@ var removeCmd = &cobra.Command{
Use: "remove",
Short: "Remove a shortened URL and delete the associated repository.",
Long: `Remove a shortened URL and delete the associated repository. Specify
the URL with it's associated repository name (may contains more than 1 repo separated by space as parameters).
the URL using it's associated repository name (optionally delete multiple repos with a space-separated list of names).
Example:
$ shorten remove go
Expand Down Expand Up @@ -50,13 +51,14 @@ func findRepo(repoName string) (entry, error) {
}
}

return entry{}, fmt.Errorf("repository `%s` not found", repoName)
return entry{}, errors.New("repository not found")
}

func removeRepo(repoName string) error {
repo, err := findRepo(repoName)
if err != nil {
return err
fmt.Printf("Repository `%s` not found.\n", repoName)
return nil
}

_, err = client.Repositories.Delete(ctx, repo.Owner, repo.Repo)
Expand Down

0 comments on commit 588448d

Please sign in to comment.