added bash completion for overlay commands

This commit is contained in:
Christian Goll
2022-06-08 15:49:55 +02:00
parent 53667157c5
commit 69c058f106
7 changed files with 64 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
package chmod
import (
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/spf13/cobra"
)
@@ -13,6 +14,13 @@ var (
Example: "wwctl overlay chmod default /etc/hostname.ww 0660",
RunE: CobraRunE,
Args: cobra.ExactArgs(3),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
list, _ := overlay.FindOverlays()
return list, cobra.ShellCompDirectiveNoFileComp
},
}
)

View File

@@ -1,6 +1,9 @@
package chown
import "github.com/spf13/cobra"
import (
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/spf13/cobra"
)
var (
baseCmd = &cobra.Command{
@@ -10,6 +13,13 @@ var (
Long: "This command changes the ownership of a FILE within the system or runtime OVERLAY_NAME\nto the user specified by UID. Optionally, it will also change group ownership to GID.",
RunE: CobraRunE,
Args: cobra.RangeArgs(3, 4),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
list, _ := overlay.FindOverlays()
return list, cobra.ShellCompDirectiveNoFileComp
},
}
)

View File

@@ -1,6 +1,7 @@
package delete
import (
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/spf13/cobra"
)
@@ -13,6 +14,13 @@ var (
RunE: CobraRunE,
Args: cobra.RangeArgs(1, 2),
Aliases: []string{"rm", "del"},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
list, _ := overlay.FindOverlays()
return list, cobra.ShellCompDirectiveNoFileComp
},
}
Force bool
Parents bool

View File

@@ -1,6 +1,7 @@
package edit
import (
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/spf13/cobra"
)
@@ -12,6 +13,13 @@ var (
Long: "This command will open the FILE for editing or create a new file within the\nOVERLAY_NAME. Note: files created with a '.ww' suffix will always be\nparsed as Warewulf template files, and the suffix will be removed automatically.",
RunE: CobraRunE,
Args: cobra.ExactArgs(2),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
list, _ := overlay.FindOverlays()
return list, cobra.ShellCompDirectiveNoFileComp
},
}
ListFiles bool
CreateDirs bool

View File

@@ -1,6 +1,9 @@
package imprt
import "github.com/spf13/cobra"
import (
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/spf13/cobra"
)
var (
baseCmd = &cobra.Command{
@@ -11,6 +14,13 @@ var (
RunE: CobraRunE,
Args: cobra.RangeArgs(2, 3),
Aliases: []string{"cp"},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
list, _ := overlay.FindOverlays()
return list, cobra.ShellCompDirectiveNoFileComp
},
}
PermMode int32
NoOverlayUpdate bool

View File

@@ -1,6 +1,7 @@
package list
import (
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/spf13/cobra"
)
@@ -14,6 +15,13 @@ var (
Args: cobra.MinimumNArgs(0),
Aliases: []string{"ls"},
ValidArgs: []string{"system", "runtime"},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
list, _ := overlay.FindOverlays()
return list, cobra.ShellCompDirectiveNoFileComp
},
}
ListContents bool
ListLong bool

View File

@@ -4,6 +4,7 @@ import (
"log"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/spf13/cobra"
)
@@ -16,14 +17,21 @@ var (
RunE: CobraRunE,
Aliases: []string{"cat"},
Args: cobra.ExactArgs(2),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
list, _ := overlay.FindOverlays()
return list, cobra.ShellCompDirectiveNoFileComp
},
}
NodeName string
Quiet bool
)
func init() {
baseCmd.PersistentFlags().StringVarP(&NodeName, "name", "n", "", "node used for the variables in the template")
if err := baseCmd.RegisterFlagCompletionFunc("name", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
baseCmd.PersistentFlags().StringVarP(&NodeName, "render", "r", "", "node used for the variables in the template")
if err := baseCmd.RegisterFlagCompletionFunc("render", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
nodeDB, _ := node.New()
nodes, _ := nodeDB.FindAllNodes()
var node_names []string