Skip to content

Commit 67a95cd

Browse files
committed
fix(secretflag) use title case when printing flag usage
1 parent 70b40bb commit 67a95cd

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

docs/stackit_beta_alb_observability-credentials_add.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ stackit beta alb observability-credentials add [flags]
2222
```
2323
-d, --displayname string Displayname for the credentials
2424
-h, --help Help for "stackit beta alb observability-credentials add"
25-
--password string password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.
25+
--password string Password. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.
2626
-u, --username string Username for the credentials
2727
```
2828

internal/pkg/flags/secret.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77

88
"github.com/spf13/cobra"
99
"github.com/spf13/pflag"
10+
"golang.org/x/text/cases"
11+
"golang.org/x/text/language"
1012

1113
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1214
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
@@ -54,7 +56,8 @@ func (f *secretFlag) Type() string {
5456
}
5557

5658
func (f *secretFlag) Usage() string {
57-
return fmt.Sprintf("%s. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.", f.name)
59+
name := cases.Title(language.AmericanEnglish).String(f.name)
60+
return fmt.Sprintf("%s. Can be a string (deprecated) or a file path, if prefixed with '@' (example: @./secret.txt). Will be read from stdin when empty.", name)
5861
}
5962

6063
func SecretFlagToStringPointer(p *print.Printer, cmd *cobra.Command, flag string) *string {

internal/pkg/flags/secret_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package flags
22

33
import (
4+
"fmt"
45
"io"
6+
"strings"
57
"testing"
68
"testing/fstest"
79

@@ -122,3 +124,39 @@ func TestSecretFlag(t *testing.T) {
122124
})
123125
}
124126
}
127+
128+
func TestSecretFlag_Usage(t *testing.T) {
129+
t.Parallel()
130+
tests := []struct{
131+
in string
132+
want string
133+
} {
134+
{
135+
in: "password",
136+
want: "Password",
137+
},
138+
{
139+
in: "Password",
140+
want: "Password",
141+
},
142+
{
143+
in: "",
144+
want: "",
145+
},
146+
{
147+
in: "secret-key",
148+
want: "Secret-Key",
149+
},
150+
}
151+
for _, tt := range tests {
152+
t.Run(fmt.Sprintf("%q -> %q", tt.in, tt.want), func(t *testing.T) {
153+
t.Parallel()
154+
params := testparams.NewTestParams()
155+
flag := SecretFlag(tt.in, params.CmdParams)
156+
got := flag.Usage()
157+
if !strings.HasPrefix(got, tt.want) {
158+
t.Fatalf("unexpected usage: got %q, want %q", got, tt.want)
159+
}
160+
})
161+
}
162+
}

0 commit comments

Comments
 (0)