Skip to content

Commit b42533e

Browse files
authored
refactor: use a func to print input model debug output (#1016)
1 parent e687b71 commit b42533e

File tree

363 files changed

+377
-3237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

363 files changed

+377
-3237
lines changed

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
106106
}
107107

108108
// Write the input model to the debug logs
109-
if p.IsVerbosityDebug() {
110-
modelStr, err := print.BuildDebugStrFromInputModel(model)
111-
if err != nil {
112-
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
113-
} else {
114-
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
115-
}
116-
}
117-
109+
p.DebugInputModel(model)
118110
return &model, nil
119111
}
120112

CONTRIBUTION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Please remember to run `make generate-docs` after your changes to keep the comma
5353

5454
Below is a typical structure of a CLI command:
5555

56-
https://github.com/stackitcloud/stackit-cli/blob/85ce44cd18d11169f2548d8657031b5fc6f94740/.github/docs/contribution-guide/cmd.go#L23-L156
56+
https://github.com/stackitcloud/stackit-cli/blob/main/.github/docs/contribution-guide/cmd.go
5757

5858
Please remember to always add unit tests for `parseInput`, `buildRequest` (in `bar_test.go`), and any other util functions used.
5959

@@ -87,7 +87,7 @@ If you want to add a command that uses a STACKIT service `foo` that was not yet
8787
1. This is done in `internal/pkg/services/foo/client/client.go`
8888
2. Below is an example of a typical `client.go` file structure:
8989

90-
https://github.com/stackitcloud/stackit-cli/blob/85ce44cd18d11169f2548d8657031b5fc6f94740/.github/docs/contribution-guide/client.go#L12-L35
90+
https://github.com/stackitcloud/stackit-cli/blob/main/.github/docs/contribution-guide/client.go
9191

9292
### Local development
9393

internal/cmd/affinity-groups/create/create.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
112112
Policy: flags.FlagToStringValue(p, cmd, policyFlag),
113113
}
114114

115-
if p.IsVerbosityDebug() {
116-
modelStr, err := print.BuildDebugStrFromInputModel(model)
117-
if err != nil {
118-
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
119-
} else {
120-
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
121-
}
122-
}
123-
115+
p.DebugInputModel(model)
124116
return &model, nil
125117
}
126118

internal/cmd/affinity-groups/delete/delete.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM
101101
AffinityGroupId: cliArgs[0],
102102
}
103103

104-
if p.IsVerbosityDebug() {
105-
modelStr, err := print.BuildDebugStrFromInputModel(model)
106-
if err != nil {
107-
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
108-
} else {
109-
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
110-
}
111-
}
112-
104+
p.DebugInputModel(model)
113105
return &model, nil
114106
}

internal/cmd/affinity-groups/describe/describe.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, cliArgs []string) (*inputM
8484
AffinityGroupId: cliArgs[0],
8585
}
8686

87-
if p.IsVerbosityDebug() {
88-
modelStr, err := print.BuildDebugStrFromInputModel(model)
89-
if err != nil {
90-
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
91-
} else {
92-
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
93-
}
94-
}
95-
87+
p.DebugInputModel(model)
9688
return &model, nil
9789
}
9890

internal/cmd/affinity-groups/list/list.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
106106
Limit: limit,
107107
}
108108

109-
if p.IsVerbosityDebug() {
110-
modelStr, err := print.BuildDebugStrFromInputModel(model)
111-
if err != nil {
112-
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
113-
} else {
114-
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
115-
}
116-
}
117-
109+
p.DebugInputModel(model)
118110
return &model, nil
119111
}
120112

internal/cmd/auth/activate-service-account/activate_service_account.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) *inputModel {
121121
OnlyPrintAccessToken: flags.FlagToBoolValue(p, cmd, onlyPrintAccessTokenFlag),
122122
}
123123

124-
if p.IsVerbosityDebug() {
125-
modelStr, err := print.BuildDebugStrFromInputModel(model)
126-
if err != nil {
127-
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
128-
} else {
129-
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
130-
}
131-
}
132-
124+
p.DebugInputModel(model)
133125
return &model
134126
}
135127

internal/cmd/auth/get-access-token/get_access_token.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
7777
GlobalFlagModel: globalFlags,
7878
}
7979

80-
if p.IsVerbosityDebug() {
81-
modelStr, err := print.BuildDebugStrFromInputModel(model)
82-
if err != nil {
83-
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
84-
} else {
85-
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
86-
}
87-
}
88-
80+
p.DebugInputModel(model)
8981
return &model, nil
9082
}

internal/cmd/beta/alb/create/create.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
118118
Configuration: flags.FlagToStringPointer(p, cmd, configurationFlag),
119119
}
120120

121-
if p.IsVerbosityDebug() {
122-
modelStr, err := print.BuildDebugStrFromInputModel(model)
123-
if err != nil {
124-
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
125-
} else {
126-
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
127-
}
128-
}
129-
121+
p.DebugInputModel(model)
130122
return &model, nil
131123
}
132124

internal/cmd/beta/alb/delete/delete.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
8787
Name: loadbalancerName,
8888
}
8989

90-
if p.IsVerbosityDebug() {
91-
modelStr, err := print.BuildDebugStrFromInputModel(model)
92-
if err != nil {
93-
p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err)
94-
} else {
95-
p.Debug(print.DebugLevel, "parsed input values: %s", modelStr)
96-
}
97-
}
98-
90+
p.DebugInputModel(model)
9991
return &model, nil
10092
}
10193

0 commit comments

Comments
 (0)