refactor to overlay info
This commit is contained in:
committed by
Jonathon Anderson
parent
d1d398d2ff
commit
983a359c00
@@ -1,4 +1,4 @@
|
||||
package variables
|
||||
package info
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package variables
|
||||
package info
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -1,4 +1,4 @@
|
||||
package variables
|
||||
package info
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
|
||||
var (
|
||||
baseCmd = &cobra.Command{
|
||||
Use: "variables [flags] OVERLAY_NAME FILE_PATH",
|
||||
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"},
|
||||
Aliases: []string{"vars", "tags", "information"},
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: CobraRunE,
|
||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
@@ -1,7 +1,9 @@
|
||||
package list
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/table"
|
||||
@@ -30,7 +32,11 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error {
|
||||
if vars.ShowPath {
|
||||
locationStr = "PATH"
|
||||
}
|
||||
t.AddHeader("OVERLAY NAME", "FILES/DIRS", locationStr)
|
||||
if vars.ListLong {
|
||||
t.AddHeader("PERM MODE", "UID", "GID", "OVERLAY", "FILE PATH", locationStr)
|
||||
} else {
|
||||
t.AddHeader("OVERLAY NAME", "FILES/DIRS", locationStr)
|
||||
}
|
||||
|
||||
for _, name := range overlays {
|
||||
overlay_, err := overlay.Get(name)
|
||||
@@ -43,21 +49,39 @@ func CobraRunE(vars *variables) func(cmd *cobra.Command, args []string) error {
|
||||
files := util.FindFiles(overlay_.Rootfs())
|
||||
|
||||
wwlog.Debug("Iterating overlay rootfs: %s", overlay_.Rootfs())
|
||||
locLine := strconv.FormatBool(overlay_.IsSiteOverlay())
|
||||
if vars.ShowPath {
|
||||
locLine = overlay_.Path()
|
||||
}
|
||||
if vars.ListContents || vars.ListLong {
|
||||
var fileCount int
|
||||
if vars.ListLong {
|
||||
for file := range files {
|
||||
t.AddLine(name, files[file], locLine)
|
||||
fileCount++
|
||||
}
|
||||
if fileCount == 0 {
|
||||
t.AddLine(name, 0, locLine)
|
||||
s, err := os.Stat(overlay_.File(files[file]))
|
||||
if err != nil {
|
||||
wwlog.Warn("%s: %s: %s", name, files[file], err)
|
||||
continue
|
||||
}
|
||||
fileMode := s.Mode()
|
||||
perms := fileMode & os.ModePerm
|
||||
sys := s.Sys()
|
||||
locLine := strconv.FormatBool(overlay_.IsSiteOverlay())
|
||||
if vars.ShowPath {
|
||||
locLine = overlay_.Path()
|
||||
}
|
||||
t.AddLine(perms, sys.(*syscall.Stat_t).Uid, sys.(*syscall.Stat_t).Gid, name, files[file], locLine)
|
||||
}
|
||||
} else {
|
||||
t.AddLine(name, len(files), locLine)
|
||||
locLine := strconv.FormatBool(overlay_.IsSiteOverlay())
|
||||
if vars.ShowPath {
|
||||
locLine = overlay_.Path()
|
||||
}
|
||||
if vars.ListContents {
|
||||
var fileCount int
|
||||
for file := range files {
|
||||
t.AddLine(name, files[file], locLine)
|
||||
fileCount++
|
||||
}
|
||||
if fileCount == 0 {
|
||||
t.AddLine(name, 0, locLine)
|
||||
}
|
||||
} else {
|
||||
t.AddLine(name, len(files), locLine)
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Print()
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/delete"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/edit"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/imprt"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/info"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/list"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/mkdir"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/show"
|
||||
"github.com/warewulf/warewulf/internal/app/wwctl/overlay/variables"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -36,7 +36,7 @@ func init() {
|
||||
baseCmd.AddCommand(imprt.GetCommand())
|
||||
baseCmd.AddCommand(chmod.GetCommand())
|
||||
baseCmd.AddCommand(chown.GetCommand())
|
||||
baseCmd.AddCommand(variables.GetCommand())
|
||||
baseCmd.AddCommand(info.GetCommand())
|
||||
}
|
||||
|
||||
// GetRootCommand returns the root cobra.Command for the application.
|
||||
|
||||
Reference in New Issue
Block a user