mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
Added the project auto completion code (#959)
* Added the project auto completion code Signed-off-by: mik-dass <mrinald7@gmail.com> * Added getUserTypedCommands function fro getting user typed entitites Signed-off-by: mik-dass <mrinald7@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/redhat-developer/odo/pkg/odo/util"
|
||||
"github.com/redhat-developer/odo/pkg/odo/util/completion"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -151,6 +152,7 @@ func printUnmountedStorage(client *occlient.Client, applicationName string) {
|
||||
|
||||
func addProjectFlag(cmd *cobra.Command) {
|
||||
cmd.Flags().String(util.ProjectFlagName, "", "Project, defaults to active project")
|
||||
completion.RegisterCommandFlagHandler(cmd, "project", completion.ProjectNameCompletionHandler)
|
||||
}
|
||||
|
||||
func addComponentFlag(cmd *cobra.Command) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
|
||||
"github.com/redhat-developer/odo/pkg/odo/util"
|
||||
"github.com/redhat-developer/odo/pkg/odo/util/completion"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -200,6 +201,7 @@ func init() {
|
||||
projectGetCmd.Flags().BoolVarP(&projectShortFlag, "short", "q", false, "If true, display only the project name")
|
||||
projectSetCmd.Flags().BoolVarP(&projectShortFlag, "short", "q", false, "If true, display only the project name")
|
||||
projectDeleteCmd.Flags().BoolVarP(&projectForceDeleteFlag, "force", "f", false, "Delete project without prompting")
|
||||
projectDeleteCmd.Flags().BoolVarP(&projectShortFlag, "short", "q", false, "Delete project without prompting")
|
||||
|
||||
projectCmd.Flags().AddFlagSet(projectGetCmd.Flags())
|
||||
projectCmd.AddCommand(projectGetCmd)
|
||||
@@ -212,5 +214,8 @@ func init() {
|
||||
projectCmd.Annotations = map[string]string{"command": "other"}
|
||||
projectCmd.SetUsageTemplate(cmdUsageTemplate)
|
||||
|
||||
completion.RegisterCommandHandler(projectSetCmd, completion.ProjectNameCompletionHandler)
|
||||
completion.RegisterCommandHandler(projectDeleteCmd, completion.ProjectNameCompletionHandler)
|
||||
|
||||
rootCmd.AddCommand(projectCmd)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/redhat-developer/odo/pkg/occlient"
|
||||
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
|
||||
"github.com/redhat-developer/odo/pkg/odo/util/completion"
|
||||
"github.com/spf13/cobra"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
ktesting "k8s.io/client-go/testing"
|
||||
@@ -20,17 +21,20 @@ func TestCompletions(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
handler completion.ContextualizedPredictor
|
||||
cmd *cobra.Command
|
||||
last string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "Completing service create without input returns all available service class external names",
|
||||
handler: completion.ServiceClassCompletionHandler,
|
||||
cmd: serviceCreateCmd,
|
||||
want: []string{"foo", "bar", "boo"},
|
||||
},
|
||||
{
|
||||
name: "Completing service delete without input returns all available service instances",
|
||||
handler: completion.ServiceCompletionHandler,
|
||||
cmd: serviceDeleteCmd,
|
||||
want: []string{"foo"},
|
||||
},
|
||||
}
|
||||
@@ -67,7 +71,9 @@ func TestCompletions(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := complete.Args{Last: tt.last}
|
||||
got := tt.handler(nil, a, context)
|
||||
|
||||
got := tt.handler(tt.cmd, a, context)
|
||||
|
||||
if !equal(got, tt.want) {
|
||||
t.Errorf("Failed %s: got: %q, want: %q", t.Name(), got, tt.want)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user