mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
@@ -2,11 +2,13 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
|
||||
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
|
||||
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
|
||||
"github.com/redhat-developer/odo/pkg/odo/util/completion"
|
||||
|
||||
"github.com/redhat-developer/odo/pkg/storage"
|
||||
"github.com/redhat-developer/odo/pkg/util"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -279,4 +281,8 @@ func init() {
|
||||
storageCmd.SetUsageTemplate(cmdUsageTemplate)
|
||||
|
||||
rootCmd.AddCommand(storageCmd)
|
||||
|
||||
completion.RegisterCommandHandler(storageDeleteCmd, completion.StorageDeleteCompletionHandler)
|
||||
completion.RegisterCommandHandler(storageMountCmd, completion.StorageMountCompletionHandler)
|
||||
completion.RegisterCommandHandler(storageUnmountCmd, completion.StorageUnMountCompletionHandler)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
|
||||
"github.com/redhat-developer/odo/pkg/project"
|
||||
"github.com/redhat-developer/odo/pkg/service"
|
||||
"github.com/redhat-developer/odo/pkg/storage"
|
||||
"github.com/redhat-developer/odo/pkg/url"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -100,3 +101,60 @@ var URLCompletionHandler = func(cmd *cobra.Command, args parsedArgs, context *ge
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StorageDeleteCompletionHandler provides storage name completion for storage delete
|
||||
var StorageDeleteCompletionHandler = func(cmd *cobra.Command, args parsedArgs, context *genericclioptions.Context) (completions []string) {
|
||||
completions = make([]string, 0)
|
||||
storages, err := storage.List(context.Client, context.Component(), context.Application)
|
||||
if err != nil {
|
||||
return completions
|
||||
}
|
||||
|
||||
for _, storage := range storages {
|
||||
// we found the storage name in the list which means
|
||||
// that the storage name has been already selected by the user so no need to suggest more
|
||||
if val, ok := args.commands[storage.Name]; ok && val {
|
||||
return nil
|
||||
}
|
||||
completions = append(completions, storage.Name)
|
||||
}
|
||||
return completions
|
||||
}
|
||||
|
||||
// StorageMountCompletionHandler provides storage name completion for storage mount
|
||||
var StorageMountCompletionHandler = func(cmd *cobra.Command, args parsedArgs, context *genericclioptions.Context) (completions []string) {
|
||||
completions = make([]string, 0)
|
||||
storages, err := storage.ListUnmounted(context.Client, context.Application)
|
||||
if err != nil {
|
||||
return completions
|
||||
}
|
||||
|
||||
for _, storage := range storages {
|
||||
// we found the storage name in the list which means
|
||||
// that the storage name has been already selected by the user so no need to suggest more
|
||||
if val, ok := args.commands[storage.Name]; ok && val {
|
||||
return nil
|
||||
}
|
||||
completions = append(completions, storage.Name)
|
||||
}
|
||||
return completions
|
||||
}
|
||||
|
||||
// StorageUnMountCompletionHandler provides storage name completion for storage unmount
|
||||
var StorageUnMountCompletionHandler = func(cmd *cobra.Command, args parsedArgs, context *genericclioptions.Context) (completions []string) {
|
||||
completions = make([]string, 0)
|
||||
storages, err := storage.ListMounted(context.Client, context.Component(), context.Application)
|
||||
if err != nil {
|
||||
return completions
|
||||
}
|
||||
|
||||
for _, storage := range storages {
|
||||
// we found the storage name in the list which means
|
||||
// that the storage name has been already selected by the user so no need to suggest more
|
||||
if val, ok := args.commands[storage.Name]; ok && val {
|
||||
return nil
|
||||
}
|
||||
completions = append(completions, storage.Name)
|
||||
}
|
||||
return completions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user