summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/cli/interface.go2
-rw-r--r--internal/cli/query.go2
-rw-r--r--internal/prompt/cloud.go2
-rw-r--r--internal/prompt/git.go8
-rw-r--r--internal/rtree/index.go2
-rw-r--r--internal/rtree/init.go2
-rw-r--r--internal/rtree/remote.go4
-rw-r--r--internal/rtree/repo.go2
-rw-r--r--internal/rtree/shared_test.go4
9 files changed, 14 insertions, 14 deletions
diff --git a/internal/cli/interface.go b/internal/cli/interface.go
index 5e41894..a5879f6 100644
--- a/internal/cli/interface.go
+++ b/internal/cli/interface.go
@@ -126,7 +126,7 @@ func (i *Implementation) Run(c Command) error {
func (i *Implementation) CaptureStdout(c Command) (string, error) {
var buf bytes.Buffer
err := i.commandRunner(c, nil, &buf, i.stderr)
- return string(buf.Bytes()), err
+ return buf.String(), err
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/internal/cli/query.go b/internal/cli/query.go
index a2bd004..3aaa495 100644
--- a/internal/cli/query.go
+++ b/internal/cli/query.go
@@ -154,7 +154,7 @@ OUTER:
}
func removeDisplayLines(stdout io.Writer, n int) {
- for idx := 0; idx < n; idx++ {
+ for range n {
stdout.Write([]byte("\x1B[A\x1B[2K"))
}
}
diff --git a/internal/prompt/cloud.go b/internal/prompt/cloud.go
index 624f56d..14cd18a 100644
--- a/internal/prompt/cloud.go
+++ b/internal/prompt/cloud.go
@@ -86,7 +86,7 @@ func getKubernetesFieldViaU8S() string {
context string
namespace string
)
- for _, line := range strings.Split(string(stdout), "\n") {
+ for line := range strings.SplitSeq(string(stdout), "\n") {
fields := strings.SplitN(strings.TrimSpace(line), "=", 2)
if len(fields) != 2 {
continue
diff --git a/internal/prompt/git.go b/internal/prompt/git.go
index 6f0cf1d..26291c4 100644
--- a/internal/prompt/git.go
+++ b/internal/prompt/git.go
@@ -57,12 +57,12 @@ func findRepo(path string) (*gitRepo, error) {
if err != nil {
return nil, err
}
- for _, line := range strings.Split(string(bytes), "\n") {
+ for line := range strings.SplitSeq(string(bytes), "\n") {
line = strings.TrimSpace(line)
- if strings.HasPrefix(line, "gitdir:") {
+ if gitDir, ok := strings.CutPrefix(line, "gitdir:"); ok {
return &gitRepo{
RootPath: path,
- GitDir: filepath.Join(path, strings.TrimSpace(strings.TrimPrefix(line, "gitdir:"))),
+ GitDir: filepath.Join(path, strings.TrimSpace(gitDir)),
}, nil
}
}
@@ -115,7 +115,7 @@ func tryReadFromPackedRefs(repo *gitRepo, refSpec string) string {
if err != nil {
return ""
}
- for _, line := range strings.Split(string(bytes), "\n") {
+ for line := range strings.SplitSeq(string(bytes), "\n") {
line = strings.TrimSpace(line)
if line == "" || strings.HasPrefix(line, "#") {
continue
diff --git a/internal/rtree/index.go b/internal/rtree/index.go
index 09ababa..a329cd7 100644
--- a/internal/rtree/index.go
+++ b/internal/rtree/index.go
@@ -57,7 +57,7 @@ func ReadIndex() (*Index, []error) {
//validate YAML
var errs []error
- missing := func(key string, args ...interface{}) {
+ missing := func(key string, args ...any) {
errs = append(errs, fmt.Errorf("read %s: missing \"%s\"",
IndexPath, fmt.Sprintf(key, args...),
))
diff --git a/internal/rtree/init.go b/internal/rtree/init.go
index 7121af9..13947a8 100644
--- a/internal/rtree/init.go
+++ b/internal/rtree/init.go
@@ -83,7 +83,7 @@ func Init() bool {
}
rx := regexp.MustCompile(`^url\.([^=]+)\.insteadof=(.+)$`)
- for _, line := range strings.Split(out, "\n") {
+ for line := range strings.SplitSeq(out, "\n") {
match := rx.FindStringSubmatch(line)
if match == nil {
continue
diff --git a/internal/rtree/remote.go b/internal/rtree/remote.go
index 3d443aa..a8d5564 100644
--- a/internal/rtree/remote.go
+++ b/internal/rtree/remote.go
@@ -102,13 +102,13 @@ func (u RemoteURL) CheckoutPath() (string, error) {
}
// MarshalYAML implements the yaml.Marshaler interface.
-func (u RemoteURL) MarshalYAML() (interface{}, error) {
+func (u RemoteURL) MarshalYAML() (any, error) {
//store URLs in the index in the canonical format
return u.CanonicalURL(), nil
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
-func (u *RemoteURL) UnmarshalYAML(unmarshal func(interface{}) error) error {
+func (u *RemoteURL) UnmarshalYAML(unmarshal func(any) error) error {
var s string
err := unmarshal(&s)
if err == nil {
diff --git a/internal/rtree/repo.go b/internal/rtree/repo.go
index 2267666..397df4f 100644
--- a/internal/rtree/repo.go
+++ b/internal/rtree/repo.go
@@ -71,7 +71,7 @@ func NewRepoFromAbsolutePath(path string) (repo Repo, err error) {
return
}
- for _, line := range strings.Split(out, "\n") {
+ for line := range strings.SplitSeq(out, "\n") {
match := remoteConfigRx.FindStringSubmatch(line)
if match == nil {
continue
diff --git a/internal/rtree/shared_test.go b/internal/rtree/shared_test.go
index e26eb11..0a5e2df 100644
--- a/internal/rtree/shared_test.go
+++ b/internal/rtree/shared_test.go
@@ -146,8 +146,8 @@ func Recorded(lines ...string) (cs []RecordedCommand) {
cs = make([]RecordedCommand, len(lines))
for idx, line := range lines {
cmdline := strings.Fields(line)
- if strings.HasPrefix(cmdline[0], "@") {
- cs[idx].Cmd.WorkDir = strings.TrimPrefix(cmdline[0], "@")
+ if workDir, ok := strings.CutPrefix(cmdline[0], "@"); ok {
+ cs[idx].Cmd.WorkDir = workDir
cmdline = cmdline[1:]
}
cs[idx].Cmd.Program = cmdline