Skip to content

Commit 56527af

Browse files
Merge pull request #382 from mrWinston/osd-16139-cluster-context-check-output-format-earlier
[OSD-16139] check cluster context output format before gathering data
2 parents d475242 + 38b4932 commit 56527af

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

cmd/cluster/context.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ func (o *contextOptions) complete(cmd *cobra.Command, args []string) error {
159159

160160
func (o *contextOptions) run() error {
161161

162+
var printFunc func(*contextData)
163+
switch o.output {
164+
case shortOutputConfigValue:
165+
printFunc = o.printShortOutput
166+
case longOutputConfigValue:
167+
printFunc = o.printLongOutput
168+
case jsonOutputConfigValue:
169+
printFunc = o.printJsonOutput
170+
default:
171+
return fmt.Errorf("Unknown Output Format: %s", o.output)
172+
}
173+
162174
currentData, dataErrors := o.generateContextData()
163175
if currentData == nil {
164176
fmt.Fprintf(os.Stderr, "Failed to query cluster info: %+v", dataErrors)
@@ -172,16 +184,7 @@ func (o *contextOptions) run() error {
172184
}
173185
}
174186

175-
switch o.output {
176-
case shortOutputConfigValue:
177-
o.printShortOutput(currentData)
178-
case longOutputConfigValue:
179-
o.printLongOutput(currentData)
180-
case jsonOutputConfigValue:
181-
o.printJsonOutput(currentData)
182-
default:
183-
return fmt.Errorf("Unknown Output Format: %s", o.output)
184-
}
187+
printFunc(currentData)
185188

186189
return nil
187190
}

0 commit comments

Comments
 (0)