Skip to content

Commit bd7f31a

Browse files
committed
Refinement: Examples and descriptions for --disable-writing
1 parent 4f25d16 commit bd7f31a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

internal/cmd/ske/kubeconfig/create/create.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func NewCmd(p *print.Printer) *cobra.Command {
6666
`Create a kubeconfig for the SKE cluster with name "my-cluster" in a custom filepath`,
6767
"$ stackit ske kubeconfig create my-cluster --filepath /path/to/config"),
6868
examples.NewExample(
69-
`Get a kubeconfig for the SKE cluster with name "my-cluster" without writing it to a file. `,
70-
""),
69+
`Get a kubeconfig for the SKE cluster with name "my-cluster" without writing it to a file and format the output as json`,
70+
"$ stackit ske kubeconfig create my-cluster --disable-writing --output-format json"),
7171
),
7272
RunE: func(cmd *cobra.Command, args []string) error {
7373
ctx := context.Background()
@@ -154,7 +154,7 @@ func configureFlags(cmd *cobra.Command) {
154154
cmd.Flags().BoolP(loginFlag, "l", false, "Create a login kubeconfig that obtains valid credentials via the STACKIT CLI. This flag is mutually exclusive with the expiration flag.")
155155
cmd.Flags().StringP(expirationFlag, "e", "", "Expiration time for the kubeconfig in seconds(s), minutes(m), hours(h), days(d) or months(M). Example: 30d. By default, expiration time is 1h")
156156
cmd.Flags().String(filepathFlag, "", "Path to create the kubeconfig file. By default, the kubeconfig is created as 'config' in the .kube folder, in the user's home directory.")
157-
cmd.Flags().Bool(disableWritingFlag, false, fmt.Sprintf("Disable the writing of kubeconfig. Add --%s to display the kubeconfig.", globalflags.OutputFormatFlag))
157+
cmd.Flags().Bool(disableWritingFlag, false, fmt.Sprintf("Disable the writing of kubeconfig. Set the output format to json or yaml using the --%s flag to display the kubeconfig.", globalflags.OutputFormatFlag))
158158

159159
cmd.MarkFlagsMutuallyExclusive(loginFlag, expirationFlag)
160160
}
@@ -182,8 +182,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
182182

183183
disableWriting := flags.FlagToBoolValue(p, cmd, disableWritingFlag)
184184

185-
isDefaultOutputFormat := globalFlags.OutputFormat != print.JSONOutputFormat && globalFlags.OutputFormat != print.YAMLOutputFormat
186-
if disableWriting && isDefaultOutputFormat {
185+
fmt.Println(globalFlags.OutputFormat)
186+
isInvalidOutputFormat := globalFlags.OutputFormat == "" || globalFlags.OutputFormat == print.NoneOutputFormat || globalFlags.OutputFormat == print.PrettyOutputFormat
187+
if disableWriting && isInvalidOutputFormat {
187188
return nil, fmt.Errorf("when setting the flag --%s, you must specify --%s as one of the values: %s",
188189
disableWritingFlag, globalflags.OutputFormatFlag, fmt.Sprintf("%s, %s", print.JSONOutputFormat, print.YAMLOutputFormat))
189190
}

0 commit comments

Comments
 (0)