From 63a3adf2126ce05f27a53fb8d6b41268277744d1 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Wed, 18 May 2022 08:42:14 +0200 Subject: [PATCH] Use strings.Cut --- context/context.go | 9 +-------- pkg/cmd/repo/default/default.go | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/context/context.go b/context/context.go index a00cd4ebe..f331e5c78 100644 --- a/context/context.go +++ b/context/context.go @@ -112,7 +112,7 @@ func (r *ResolvedRemotes) BaseRepo(io *iostreams.IOStreams) (ghrepo.Interface, e } // determine corresponding git remote - owner, repo, _ := cut(baseName, "/") + owner, repo, _ := strings.Cut(baseName, "/") selectedRepo := ghrepo.New(owner, repo) resolution := "base" remote, _ := r.RemoteForRepo(selectedRepo) @@ -184,10 +184,3 @@ func (r *ResolvedRemotes) RemoteForRepo(repo ghrepo.Interface) (*Remote, error) } return nil, errors.New("not found") } - -func cut(s, sep string) (before, after string, found bool) { - if i := strings.Index(s, sep); i >= 0 { - return s[:i], s[i+len(sep):], true - } - return s, "", false -} diff --git a/pkg/cmd/repo/default/default.go b/pkg/cmd/repo/default/default.go index 0418adaf0..0bc53217a 100644 --- a/pkg/cmd/repo/default/default.go +++ b/pkg/cmd/repo/default/default.go @@ -150,7 +150,7 @@ func defaultRun(opts *DefaultOptions) error { return err } - owner, repo, _ := cut(selectedName, "/") + owner, repo, _ := strings.Cut(selectedName, "/") selectedRepo = ghrepo.New(owner, repo) } } @@ -202,10 +202,3 @@ func setDefaultRepo(remote *context.Remote, resolution string) error { func unsetDefaultRepo(remote *context.Remote) error { return git.UnsetRemoteResolution(remote.Name) } - -func cut(s, sep string) (before, after string, found bool) { - if i := strings.Index(s, sep); i >= 0 { - return s[:i], s[i+len(sep):], true - } - return s, "", false -}