mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Cleanup completion for kustomize
This commit is contained in:
@@ -9,6 +9,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/cmd/config/complete"
|
||||||
"sigs.k8s.io/kustomize/cmd/config/configcobra"
|
"sigs.k8s.io/kustomize/cmd/config/configcobra"
|
||||||
"sigs.k8s.io/kustomize/kyaml/commandutil"
|
"sigs.k8s.io/kustomize/kyaml/commandutil"
|
||||||
)
|
)
|
||||||
@@ -16,7 +17,10 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
// enable the config commands
|
// enable the config commands
|
||||||
os.Setenv(commandutil.EnableAlphaCommmandsEnvName, "true")
|
os.Setenv(commandutil.EnableAlphaCommmandsEnvName, "true")
|
||||||
if err := configcobra.NewConfigCommand("").Execute(); err != nil {
|
cmd := configcobra.NewConfigCommand("")
|
||||||
|
complete.Complete(cmd).Complete("config")
|
||||||
|
|
||||||
|
if err := cmd.Execute(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,35 +6,17 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"sigs.k8s.io/kustomize/cmd/config/complete"
|
"sigs.k8s.io/kustomize/cmd/config/complete"
|
||||||
"sigs.k8s.io/kustomize/kustomize/v3/internal/commands"
|
"sigs.k8s.io/kustomize/kustomize/v3/internal/commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cmd := commands.NewDefaultCommand()
|
cmd := commands.NewDefaultCommand()
|
||||||
completion(cmd)
|
complete.Complete(cmd).Complete("kustomize")
|
||||||
|
|
||||||
if err := cmd.Execute(); err != nil {
|
if err := cmd.Execute(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// completion performs shell completion if kustomize is being called to provide
|
|
||||||
// shell completion commands.
|
|
||||||
func completion(cmd *cobra.Command) {
|
|
||||||
// bash shell completion passes the command name as the first argument
|
|
||||||
// do this after configuring cmd so it has all the subcommands
|
|
||||||
if len(os.Args) > 1 {
|
|
||||||
// use the base name in case kustomize is called with an absolute path
|
|
||||||
name := filepath.Base(os.Args[1])
|
|
||||||
if name == "kustomize" {
|
|
||||||
// complete calls kustomize with itself as an argument
|
|
||||||
complete.Complete(cmd).Complete("kustomize")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user