Skip to content
Merged
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
10 changes: 2 additions & 8 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,9 @@ 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)
for i, arg := range rawArgs {
res += arg
if i != len(rawArgs)-1 {
res += " "
}
}

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

package gotty

Expand Down
12 changes: 7 additions & 5 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 @@ -52,19 +53,20 @@ func (m *ListPrompt) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m *ListPrompt) View() string {
s := m.Prompt + "\n\n"
var builder strings.Builder
builder.WriteString(m.Prompt + "\n\n")

for i, choice := range m.Choices {
if m.cursor == i {
s += fmt.Sprintf("> %s\n", choice)
fmt.Fprintf(&builder, "> %s\n", choice)
} else {
s += choice + "\n"
builder.WriteString(choice + "\n")
}
}

s += "\nPress enter or space for select.\n"
builder.WriteString("\nPress enter or space for select.\n")

return s
return builder.String()
}

// Execute start the prompt and return the selected index
Expand Down
13 changes: 2 additions & 11 deletions internal/interactive/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Printf(format string, a ...any) (int, error) {
}

func Line(char string) string {
return makeStr(char, terminal.GetWidth())
return strings.Repeat(char, terminal.GetWidth())
}

func Center(str string) string {
Expand All @@ -56,7 +56,7 @@ func Center(str string) string {
}

func Indent(str string, indent int) string {
padding := makeStr(" ", indent)
padding := strings.Repeat(" ", indent)
lines := strings.Split(str, "\n")
for i, line := range lines {
if line != "" {
Expand All @@ -70,12 +70,3 @@ func Indent(str string, indent int) string {
func RemoveIndent(str string) string {
return strings.Trim(regexp.MustCompile("\n[ \t]*").ReplaceAllString(str, "\n"), "\n")
}

func makeStr(char string, length int) string {
str := ""
for range length {
str += char
}

return str
}
4 changes: 3 additions & 1 deletion internal/namespaces/autocomplete/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,17 @@ func TrimText(str string) string {
for i, line := range lines {
if !foundFirstNonEmptyLine {
if len(line) > 0 {
var builder strings.Builder
for _, c := range line {
if c == ' ' || c == '\t' {
strToRemove += string(c)
builder.WriteRune(c)

continue
}

break
}
strToRemove = builder.String()
foundFirstNonEmptyLine = true
}
}
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
var builder strings.Builder
builder.WriteString(prefix)
for k, v := range args {
cmd += fmt.Sprintf(" %s=%s", k, v)
fmt.Fprintf(&builder, " %s=%s", k, v)
}

return cmd
return builder.String()
}

func beforeFuncSaveConfig(config *scw.Config) core.BeforeFunc {
Expand Down
13 changes: 10 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,19 @@ func securityGroupDeleteBuilder(c *core.Command) *core.Command {
}

// Create detail message.
hint := "Attach all these instances to another security-group before deleting this one:"
var hintBuilder strings.Builder
hintBuilder.WriteString(
"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"
fmt.Fprintf(
&hintBuilder,
"\nscw instance server update %s security-group.id=$NEW_SECURITY_GROUP_ID",
s.ID,
)
}

newError.Hint = hint
newError.Hint = hintBuilder.String()

return nil, newError
}
Expand Down
12 changes: 8 additions & 4 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
var builder strings.Builder
fmt.Fprintf(&builder, `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
fmt.Fprintf(&builder, `Host %s
User %s
`,
host.name(),
host.user())
}

return bastionConfig
return builder.String()
}

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