summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rwxr-xr-xutil/gocovcat.go87
10 files changed, 14 insertions, 101 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
diff --git a/util/gocovcat.go b/util/gocovcat.go
deleted file mode 100755
index bb03f87..0000000
--- a/util/gocovcat.go
+++ /dev/null
@@ -1,87 +0,0 @@
-///usr/bin/env go run "$0" "$@"; exit $?
-
-// Copyright 2017 Luke Shumaker <lukeshu@parabola.nu>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-// Command gocovcat combines multiple go cover runs, and prints the
-// result on stdout.
-package main
-
-import (
- "bufio"
- "fmt"
- "os"
- "sort"
- "strconv"
- "strings"
-)
-
-func handleErr(err error) {
- if err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- os.Exit(1)
- }
-}
-
-func main() {
- modeBool := false
- blocks := map[string]int{}
- for _, filename := range os.Args[1:] {
- file, err := os.Open(filename)
- handleErr(err)
- buf := bufio.NewScanner(file)
- for buf.Scan() {
- line := buf.Text()
-
- if strings.HasPrefix(line, "mode: ") {
- m := strings.TrimPrefix(line, "mode: ")
- switch m {
- case "set":
- modeBool = true
- case "count", "atomic":
- // do nothing
- default:
- fmt.Fprintf(os.Stderr, "Unrecognized mode: %s\n", m)
- os.Exit(1)
- }
- } else {
- sp := strings.LastIndexByte(line, ' ')
- block := line[:sp]
- cntStr := line[sp+1:]
- cnt, err := strconv.Atoi(cntStr)
- handleErr(err)
- blocks[block] += cnt
- }
- }
- handleErr(buf.Err())
- }
- keys := make([]string, 0, len(blocks))
- for key := range blocks {
- keys = append(keys, key)
- }
- sort.Strings(keys)
- modeStr := "count"
- if modeBool {
- modeStr = "set"
- }
- fmt.Printf("mode: %s\n", modeStr)
- for _, block := range keys {
- cnt := blocks[block]
- if modeBool && cnt > 1 {
- cnt = 1
- }
- fmt.Printf("%s %d\n", block, cnt)
- }
-}