advanced command line completion for wwctl overlay

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2023-05-09 13:23:28 +02:00
committed by Christian Goll
parent 4d1711f46f
commit ff7608251a
4 changed files with 37 additions and 10 deletions

View File

@@ -433,3 +433,19 @@ func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
// Request more data.
return 0, nil, nil
}
// Get all the files as a string slice for a given overlay
func OverlayGetFiles(name string) (files []string, err error) {
baseDir := OverlaySourceDir(name)
if !util.IsDir(baseDir) {
err = fmt.Errorf("overlay %s doesn't exist", name)
return
}
err = filepath.Walk(baseDir, func(path string, info fs.FileInfo, err error) error {
if util.IsFile(path) {
files = append(files, strings.TrimPrefix(path, baseDir))
}
return nil
})
return
}