Skip to content

Commit 85ce44c

Browse files
committed
chore(doc): update contribution-guide
1 parent bf9d5c7 commit 85ce44c

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

.github/docs/contribution-guide/client.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
11
package client
22

33
import (
4-
"github.com/spf13/cobra"
54
"github.com/spf13/viper"
65
"github.com/stackitcloud/stackit-cli/internal/pkg/auth"
6+
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
77
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
8+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
9+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
10+
sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
811
"github.com/stackitcloud/stackit-sdk-go/services/foo"
912
// (...)
1013
)
1114

12-
func ConfigureClient(cmd *cobra.Command) (*foo.APIClient, error) {
13-
var err error
14-
var apiClient foo.APIClient
15-
var cfgOptions []sdkConfig.ConfigurationOption
16-
17-
authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser)
15+
func ConfigureClient(p *print.Printer, cliVersion string) (*foo.APIClient, error) {
16+
authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser)
1817
if err != nil {
1918
return nil, &errors.AuthError{}
2019
}
21-
cfgOptions = append(cfgOptions, authCfgOption, sdkConfig.WithRegion("eu01")) // Configuring region is needed if "foo" is a regional API
20+
21+
region := viper.GetString(config.RegionKey)
22+
cfgOptions := []sdkConfig.ConfigurationOption{
23+
utils.UserAgentConfigOption(cliVersion),
24+
sdkConfig.WithRegion(region), // Configuring region is needed if "foo" is a regional API
25+
authCfgOption,
26+
}
2227

2328
customEndpoint := viper.GetString(config.fooCustomEndpointKey)
2429

2530
if customEndpoint != "" {
2631
cfgOptions = append(cfgOptions, sdkConfig.WithEndpoint(customEndpoint))
2732
}
2833

29-
apiClient, err = foo.NewAPIClient(cfgOptions...)
34+
if p.IsVerbosityDebug() {
35+
cfgOptions = append(cfgOptions,
36+
sdkConfig.WithMiddleware(print.RequestResponseCapturer(p, nil)),
37+
)
38+
}
39+
40+
apiClient, err := foo.NewAPIClient(cfgOptions...)
3041
if err != nil {
42+
p.Debug(print.ErrorLevel, "create new API client: %v", err)
3143
return nil, &errors.AuthError{}
3244
}
3345

.github/docs/contribution-guide/cmd.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
1313
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1414
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1516
"github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
1617
"github.com/stackitcloud/stackit-cli/internal/pkg/services/alb/client"
1718
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
@@ -54,7 +55,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
5455
}
5556

5657
// Configure API client
57-
apiClient, err := client.ConfigureClient(params.Printer, cmd)
58+
apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion)
5859
if err != nil {
5960
return err
6061
}
@@ -66,7 +67,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
6667
return fmt.Errorf("(...): %w", err)
6768
}
6869

69-
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, cmd)
70+
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
7071
if err != nil {
7172
projectLabel = model.ProjectId
7273
}
@@ -86,22 +87,22 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
8687

8788
// Configure command flags (type, default value, and description)
8889
func configureFlags(cmd *cobra.Command) {
89-
cmd.Flags().StringP(myFlag, "defaultValue", "My flag description")
90+
cmd.Flags().StringP(someFlag, "shorthand", "defaultValue", "My flag description")
9091
}
9192

9293
// Parse user input (arguments and/or flags)
9394
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
9495
myArg := inputArgs[0]
9596

96-
globalFlags := globalflags.Parse(cmd)
97+
globalFlags := globalflags.Parse(p, cmd)
9798
if globalFlags.ProjectId == "" {
9899
return nil, &errors.ProjectIdError{}
99100
}
100101

101102
model := inputModel{
102103
GlobalFlagModel: globalFlags,
103104
MyArg: myArg,
104-
MyFlag: flags.FlagToStringPointer(cmd, myFlag),
105+
MyFlag: flags.FlagToStringPointer(p, cmd, someFlag),
105106
}
106107

107108
// Write the input model to the debug logs
@@ -119,7 +120,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
119120

120121
// Build request to the API
121122
func buildRequest(ctx context.Context, model *inputModel, apiClient *foo.APIClient) foo.ApiListInstancesRequest {
122-
req := apiClient.GetBar(ctx, model.ProjectId, model.MyArg, someParam)
123+
req := apiClient.GetBar(ctx, model.ProjectId, model.MyArg, someArg)
123124
return req
124125
}
125126

@@ -147,7 +148,7 @@ func outputResult(p *print.Printer, cmd *cobra.Command, outputFormat string, res
147148
resource := resources[i]
148149
table.AddRow(*resource.ResourceId, *resource.Name, *resource.State)
149150
}
150-
err := table.Display(cmd)
151+
err := table.Display(p)
151152
if err != nil {
152153
return fmt.Errorf("render table: %w", err)
153154
}

0 commit comments

Comments
 (0)