Return error instead of log.fatal. (#421)

Co-authored-by: Azeem Shaikh <azeems@google.com>
This commit is contained in:
Azeem Shaikh 2021-05-08 16:28:59 -07:00 committed by GitHub
parent a4768922a9
commit 29c4983fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,6 @@ package repos
import (
"errors"
"fmt"
"log"
"net/url"
"strings"
)
@ -25,6 +24,7 @@ import (
var (
ErrorUnsupportedHost = errors.New("unsupported host")
ErrorInvalidGithubURL = errors.New("invalid GitHub repo URL")
ErrorInvalidURL = errors.New("invalid repo flag")
)
type RepoURL struct {
@ -58,7 +58,7 @@ func (r *RepoURL) Set(s string) error {
const splitLen = 2
split := strings.SplitN(strings.Trim(u.Path, "/"), "/", splitLen)
if len(split) != splitLen {
log.Fatalf("invalid repo flag: [%s], pass the full repository URL", s)
return fmt.Errorf("%w: [%s], pass the full repository URL", ErrorInvalidURL, s)
}
r.Host, r.Owner, r.Repo = u.Host, split[0], split[1]