-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic shell completion for the context cmds
This commit provides dynamic shell completion for: - tanzu context delete - tanzu context use - tanzu context unset - tanzu context get - tanzu context create - tanzu context get-token - tanzu context update tae-active-resource The commit also turns off file completion for: - tanzu context list The commit also provides shell completion for all (non-boolean) flags of the "tanzu context" sub-commands. Units tests are included for each added completion. Provide a PanicOnErr function for coding errors Signed-off-by: Marc Khouzam <[email protected]>
- Loading branch information
1 parent
64cee83
commit ba0a8d4
Showing
7 changed files
with
615 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package command | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
// Completion strings for the values of the --target flag | ||
compK8sTarget = "k8s\tFor interactions with a Kubernetes cluster" | ||
compTAETarget = "tae\tFor interactions with a Application Engine endpoint" | ||
compTMCTarget = "tmc\tFor interactions with a Mission-Control endpoint" | ||
|
||
// Completion strings for the values of the --output flag | ||
compTableOutput = "table\tOutput results in human-readable format" | ||
compJSONOutput = "json\tOutput results in JSON format" | ||
compYAMLOutput = "yaml\tOutput results in YAML format" | ||
) | ||
|
||
// TODO(khouzam): move this to tanzu-plugin-runtime to be usable by plugins | ||
func completionGetOutputFormats(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { | ||
return []string{compTableOutput, compJSONOutput, compYAMLOutput}, cobra.ShellCompDirectiveNoFileComp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package command | ||
|
||
const ( | ||
// Completion output for testing the --output flag | ||
expectedOutForOutputFlag = compTableOutput + "\n" + compJSONOutput + "\n" + compYAMLOutput + "\n" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.