Skip to content

Commit a036120

Browse files
feat(core): rm secret-key, access-key, org-id, zone global flags (#686)
1 parent 9ff532a commit a036120

File tree

4 files changed

+14
-35
lines changed

4 files changed

+14
-35
lines changed

internal/core/autocomplete.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"sort"
77
"strconv"
88
"strings"
9-
10-
"github.com/scaleway/scaleway-sdk-go/logger"
119
)
1210

1311
// AutocompleteSuggestions is a list of words to be set to the shell as autocomplete suggestions.
@@ -53,10 +51,6 @@ type FlagSpec struct {
5351
}
5452

5553
func (node *AutoCompleteNode) addGlobalFlags() {
56-
node.Children["--access-key"] = NewAutoCompleteFlagNode(node, &FlagSpec{
57-
Name: "--access-key",
58-
HasVariableValue: true,
59-
})
6054
node.Children["-D"] = NewAutoCompleteFlagNode(node, &FlagSpec{
6155
Name: "-D",
6256
})
@@ -78,13 +72,11 @@ func (node *AutoCompleteNode) addGlobalFlags() {
7872
EnumValues: []string{"json", "human"},
7973
})
8074
node.Children["-p"] = NewAutoCompleteFlagNode(node, &FlagSpec{
81-
Name: "-p",
75+
Name: "-p",
76+
HasVariableValue: true,
8277
})
8378
node.Children["--profile"] = NewAutoCompleteFlagNode(node, &FlagSpec{
84-
Name: "--profile",
85-
})
86-
node.Children["--secret-key"] = NewAutoCompleteFlagNode(node, &FlagSpec{
87-
Name: "--secret-key",
79+
Name: "--profile",
8880
HasVariableValue: true,
8981
})
9082
}
@@ -273,7 +265,6 @@ func AutoComplete(ctx context.Context, leftWords []string, wordToComplete string
273265
// When a flag is found it populates `completedFlags`.
274266
// When an argument is found it populates `completedArgs`.
275267
for i, word := range append(leftWords, rightWords...) {
276-
logger.Debugf("word: '%v'", word)
277268
switch {
278269
// handle --flag=value and --flag
279270
case isFlag(word):

internal/core/autocomplete_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,19 @@ func TestAutocomplete(t *testing.T) {
129129
t.Run("scw test flower delete flower f", run(&testCase{Suggestions: nil}))
130130
// TODO: t.Run("scw test flower create leaves.0.size=", run(&testCase{Suggestions: AutocompleteSuggestions{"L", "M", "S", "XL", "XXL"}}))
131131

132-
t.Run("scw -", run(&testCase{Suggestions: AutocompleteSuggestions{"--access-key", "--debug", "--help", "--output", "--profile", "--secret-key", "-D", "-h", "-o", "-p"}}))
132+
t.Run("scw -", run(&testCase{Suggestions: AutocompleteSuggestions{"--debug", "--help", "--output", "--profile", "-D", "-h", "-o", "-p"}}))
133133
t.Run("scw test -o j", run(&testCase{Suggestions: AutocompleteSuggestions{"json"}}))
134134
t.Run("scw test flower -o ", run(&testCase{Suggestions: AutocompleteSuggestions{"human", "json"}}))
135-
t.Run("scw test flower -o json create -", run(&testCase{Suggestions: AutocompleteSuggestions{"--access-key", "--debug", "--help", "--output", "--profile", "--secret-key", "--wait", "-D", "-h", "-p", "-w"}}))
135+
t.Run("scw test flower -o json create -", run(&testCase{Suggestions: AutocompleteSuggestions{"--debug", "--help", "--output", "--profile", "--wait", "-D", "-h", "-p", "-w"}}))
136136
t.Run("scw test flower create name=p -o j", run(&testCase{Suggestions: AutocompleteSuggestions{"json"}}))
137137
t.Run("scw test flower create name=p -o json ", run(&testCase{Suggestions: AutocompleteSuggestions{"colours.0=", "leaves.0.size=", "size=", "species="}}))
138138
t.Run("scw test flower create name=p -o=json ", run(&testCase{Suggestions: AutocompleteSuggestions{"colours.0=", "leaves.0.size=", "size=", "species="}}))
139139
t.Run("scw test flower create name=p -o=jso", run(&testCase{Suggestions: nil}))
140140
t.Run("scw test flower create name=p -o", run(&testCase{Suggestions: AutocompleteSuggestions{"-o"}}))
141141
t.Run("scw test -o json flower create ", run(&testCase{Suggestions: AutocompleteSuggestions{"colours.0=", "leaves.0.size=", "name=", "size=", "species="}}))
142-
t.Run("scw test flower create name=p --secret-key xxxx ", run(&testCase{Suggestions: AutocompleteSuggestions{"colours.0=", "leaves.0.size=", "size=", "species="}}))
143-
t.Run("scw test --secret-key xxxx flower create name=p ", run(&testCase{Suggestions: AutocompleteSuggestions{"colours.0=", "leaves.0.size=", "size=", "species="}}))
144-
t.Run("scw test flower create name=p --secret-key xxxx", run(&testCase{Suggestions: nil}))
142+
t.Run("scw test flower create name=p --profile xxxx ", run(&testCase{Suggestions: AutocompleteSuggestions{"colours.0=", "leaves.0.size=", "size=", "species="}}))
143+
t.Run("scw test --profile xxxx flower create name=p ", run(&testCase{Suggestions: AutocompleteSuggestions{"colours.0=", "leaves.0.size=", "size=", "species="}}))
144+
t.Run("scw test flower create name=p --profile xxxx", run(&testCase{Suggestions: nil}))
145145
}
146146

147147
func TestWordIndex(t *testing.T) {

internal/core/client.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ func createClient(meta *meta) (*scw.Client, error) {
6767
}
6868

6969
// configErrorDetails generate a detailed error message for an invalid client option.
70-
func configErrorDetails(configKey, varEnv, flagName string) string {
70+
func configErrorDetails(configKey, varEnv string) string {
7171
// TODO: update the more info link
7272
return fmt.Sprintf(`%s can be initialised using the command "scw init".
7373
7474
After initialisation, there are three ways to provide %s:
7575
- with the Scaleway config file, in the %s key: %s;
7676
- with the %s environement variable;
77-
- with %s global CLI flag.
7877
7978
Note that the last method has the highest priority.
8079
@@ -84,7 +83,6 @@ More info: https://github.com/scaleway/scaleway-sdk-go/tree/master/scw#scaleway-
8483
configKey,
8584
scw.GetConfigPath(),
8685
varEnv,
87-
flagName,
8886
)
8987
}
9088

@@ -95,7 +93,7 @@ func validateProfile(profile *scw.Profile) error {
9593
if profile.AccessKey == nil || *profile.AccessKey == "" {
9694
return &CliError{
9795
Err: fmt.Errorf("access key is required"),
98-
Details: configErrorDetails("access_key", "SCW_ACCESS_KEY", "access-key"),
96+
Details: configErrorDetails("access_key", "SCW_ACCESS_KEY"),
9997
Hint: credentialsHint,
10098
}
10199
}
@@ -110,7 +108,7 @@ func validateProfile(profile *scw.Profile) error {
110108
if profile.SecretKey == nil || *profile.SecretKey == "" {
111109
return &CliError{
112110
Err: fmt.Errorf("secret key is required"),
113-
Details: configErrorDetails("secret_key", "SCW_SECRET_KEY", "secret-key"),
111+
Details: configErrorDetails("secret_key", "SCW_SECRET_KEY"),
114112
Hint: credentialsHint,
115113
}
116114
}
@@ -125,7 +123,7 @@ func validateProfile(profile *scw.Profile) error {
125123
if profile.DefaultOrganizationID == nil || *profile.DefaultOrganizationID == "" {
126124
return &CliError{
127125
Err: fmt.Errorf("organization ID is required"),
128-
Details: configErrorDetails("default_organization_id", "SCW_DEFAULT_ORGANIZATION_ID", "organization-id"),
126+
Details: configErrorDetails("default_organization_id", "SCW_DEFAULT_ORGANIZATION_ID"),
129127
Hint: credentialsHint,
130128
}
131129
}
@@ -140,7 +138,7 @@ func validateProfile(profile *scw.Profile) error {
140138
if profile.DefaultZone == nil || *profile.DefaultZone == "" {
141139
return &CliError{
142140
Err: fmt.Errorf("zone is required"),
143-
Details: configErrorDetails("default_zone", "SCW_DEFAULT_ZONE", "zone"),
141+
Details: configErrorDetails("default_zone", "SCW_DEFAULT_ZONE"),
144142
Hint: credentialsHint,
145143
}
146144
}

internal/core/cobra_builder.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import (
44
"strings"
55

66
"github.com/spf13/cobra"
7-
flag "github.com/spf13/pflag"
87
)
98

109
func init() {
1110
// we disable cobra command sorting to position important commands at the top when looking at the usage.
1211
cobra.EnableCommandSorting = false
13-
cobra.AddTemplateFunc("removeClientFlags", removeClientFlags)
1412
}
1513

1614
// cobraBuilder will transform a []*Command to a valid Cobra root command.
@@ -155,7 +153,7 @@ FLAGS:
155153
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}
156154
157155
GLOBAL FLAGS:
158-
{{ (removeClientFlags .InheritedFlags .Annotations.NoClient).FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .Annotations.SeeAlsos}}
156+
{{ .InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .Annotations.SeeAlsos}}
159157
160158
SEE ALSO:
161159
{{.Annotations.SeeAlsos}}{{end}}{{if .HasHelpSubCommands}}
@@ -166,14 +164,6 @@ Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
166164
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
167165
`
168166

169-
func removeClientFlags(flags *flag.FlagSet, noClient string) *flag.FlagSet {
170-
if noClient == "true" {
171-
panicOnError(flags.MarkHidden("access-key"))
172-
panicOnError(flags.MarkHidden("secret-key"))
173-
}
174-
return flags
175-
}
176-
177167
func panicOnError(err error) {
178168
if err != nil {
179169
panic(err)

0 commit comments

Comments
 (0)