Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions core/cobra_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"reflect"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -84,16 +85,16 @@ func testGetCommands() *core.Commands {
ArgsType: reflect.TypeOf(args.RawArgs{}),
AllowAnonymousClient: true,
Run: func(_ context.Context, argsI any) (i any, e error) {
res := ""
rawArgs := *argsI.(*args.RawArgs)
res := make([]string, 0, len(rawArgs))
for i, arg := range rawArgs {
res += arg
res = append(res, arg)
if i != len(rawArgs)-1 {
res += " "
res = append(res, " ")
}
}

return res, nil
return strings.Join(res, ""), nil
},
},
&core.Command{
Expand Down
3 changes: 0 additions & 3 deletions internal/gotty/resize_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build windows
// +build windows

package gotty

func subscribeToResize(resizeChan chan bool) func() {
Expand Down
8 changes: 5 additions & 3 deletions internal/interactive/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"os"
"strings"

tea "github.com/charmbracelet/bubbletea"
)
Expand Down Expand Up @@ -53,15 +54,16 @@ func (m *ListPrompt) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

func (m *ListPrompt) View() string {
s := m.Prompt + "\n\n"

choices := make([]string, 0, len(m.Choices))
for i, choice := range m.Choices {
if m.cursor == i {
s += fmt.Sprintf("> %s\n", choice)
choices = append(choices, fmt.Sprintf("> %s\n", choice))
} else {
s += choice + "\n"
choices = append(choices, choice+"\n")
}
}

s += strings.Join(choices, "")
s += "\nPress enter or space for select.\n"

return s
Expand Down
6 changes: 3 additions & 3 deletions internal/interactive/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ func RemoveIndent(str string) string {
}

func makeStr(char string, length int) string {
str := ""
chars := make([]string, 0, length)
for range length {
str += char
chars = append(chars, char)
}

return str
return strings.Join(chars, "")
}
6 changes: 3 additions & 3 deletions internal/namespaces/autocomplete/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,14 @@ func autocompleteScriptCommand() *core.Command {

func TrimText(str string) string {
foundFirstNonEmptyLine := false
strToRemove := ""
toRemove := []string(nil)
lines := strings.Split(str, "\n")
for i, line := range lines {
if !foundFirstNonEmptyLine {
if len(line) > 0 {
for _, c := range line {
if c == ' ' || c == '\t' {
strToRemove += string(c)
toRemove = append(toRemove, string(c))

continue
}
Expand All @@ -467,7 +467,7 @@ func TrimText(str string) string {
foundFirstNonEmptyLine = true
}
}
for _, c := range strToRemove {
for _, c := range strings.Join(toRemove, "") {
lines[i] = strings.Replace(lines[i], string(c), "", 1)
}
}
Expand Down
8 changes: 5 additions & 3 deletions internal/namespaces/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"path"
"regexp"
"strings"
"testing"

"github.com/scaleway/scaleway-cli/v2/core"
Expand All @@ -26,12 +27,13 @@ func checkConfig(
}

func appendArgs(prefix string, args map[string]string) string {
cmd := prefix
cmd := make([]string, 1, len(args)+1)
cmd[0] = prefix
for k, v := range args {
cmd += fmt.Sprintf(" %s=%s", k, v)
cmd = append(cmd, fmt.Sprintf("%s=%s", k, v))
}

return cmd
return strings.Join(cmd, " ")
}

func beforeFuncSaveConfig(config *scw.Config) core.BeforeFunc {
Expand Down
10 changes: 7 additions & 3 deletions internal/namespaces/instance/v1/custom_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,16 @@ func securityGroupDeleteBuilder(c *core.Command) *core.Command {
}

// Create detail message.
hint := "Attach all these instances to another security-group before deleting this one:"
hint := make([]string, 1, len(sg.SecurityGroup.Servers)+1)
hint[0] = "Attach all these instances to another security-group before deleting this one:"
for _, s := range sg.SecurityGroup.Servers {
hint += "\nscw instance server update " + s.ID + " security-group.id=$NEW_SECURITY_GROUP_ID"
hint = append(
hint,
"scw instance server update "+s.ID+" security-group.id=$NEW_SECURITY_GROUP_ID",
)
}

newError.Hint = hint
newError.Hint = strings.Join(hint, "\n")

return nil, newError
}
Expand Down
14 changes: 9 additions & 5 deletions internal/sshconfig/bastion_host.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package sshconfig

import "fmt"
import (
"fmt"
"strings"
)

type BastionHost struct {
Name string
Expand All @@ -11,22 +14,23 @@ type BastionHost struct {
}

func (b BastionHost) Config() string {
bastionConfig := fmt.Sprintf(`Host %s
bastionConfig := make([]string, 1, len(b.Hosts)+1)
bastionConfig[0] = fmt.Sprintf(`Host %s
ProxyJump bastion@%s
`,
b.name(),
b.address())

for _, host := range b.Hosts {
host.Name = fmt.Sprintf("%s.%s", host.Name, b.Name)
bastionConfig += fmt.Sprintf(`Host %s
bastionConfig = append(bastionConfig, fmt.Sprintf(`Host %s
User %s
`,
host.name(),
host.user())
host.user()))
}

return bastionConfig
return strings.Join(bastionConfig, "")
}

func (b BastionHost) name() string {
Expand Down
Loading