refactor to overlay info

This commit is contained in:
Christian Goll
2025-11-12 19:30:24 +01:00
committed by Jonathon Anderson
parent d1d398d2ff
commit 983a359c00
7 changed files with 56 additions and 22 deletions

View File

@@ -0,0 +1,38 @@
package info
import (
"github.com/spf13/cobra"
"github.com/warewulf/warewulf/internal/pkg/overlay"
)
var (
baseCmd = &cobra.Command{
Use: "info [flags] OVERLAY_NAME FILE_PATH",
Short: "Show variables for a template file in an overlay",
Long: "This command will show the variables for a given template file in a given\n" + "overlay.",
Aliases: []string{"vars", "tags", "information"},
Args: cobra.ExactArgs(2),
RunE: CobraRunE,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
return overlay.FindOverlays(), cobra.ShellCompDirectiveNoFileComp
} else if len(args) == 1 {
ov, err := overlay.Get(args[0])
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
files, err := ov.GetFiles()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
return files, cobra.ShellCompDirectiveNoFileComp
}
return nil, cobra.ShellCompDirectiveNoFileComp
},
}
)
// GetCommand returns the root cobra.Command for this application.
func GetCommand() *cobra.Command {
return baseCmd
}