Files
warewulf/internal/app/wwctl/resource/list/root.go
Christian Goll 5ff27061a3 added remote resources
Signed-off-by: Christian Goll <cgoll@suse.com>
2025-01-16 23:00:37 -07:00

34 lines
1.1 KiB
Go

package list
import (
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/node"
)
type variables struct {
all bool
}
// GetRootCommand returns the root cobra.Command for the application.
func GetCommand() *cobra.Command {
vars := variables{}
baseCmd := &cobra.Command{
DisableFlagsInUseLine: true,
Use: "list [RESOURCE]",
Short: "list resource",
Long: "This list all values the named RESOURCE. If no resource is named a list of the resources is printed.",
Aliases: []string{"show", "ls"},
RunE: CobraRunE(&vars),
Args: cobra.MaximumNArgs(1),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
nodeDB, _ := node.New()
return nodeDB.ListAllResources(), cobra.ShellCompDirectiveNoFileComp
},
}
baseCmd.PersistentFlags().BoolVarP(&vars.all, "all", "a", false, "Show all resources")
return baseCmd
}