providers/os: Add listFiles function that works like the caddy one
This commit is contained in:
		
							parent
							
								
									fa8e359ec0
								
							
						
					
					
						commit
						f9fb355c8c
					
				@ -31,6 +31,7 @@ func (this *Provider) FuncMapFor (document *step.Document) template.FuncMap {
 | 
			
		||||
		"statFile":   stat.funcStatFile,
 | 
			
		||||
		"readFile":   stat.funcReadFile,
 | 
			
		||||
		"readDir":    stat.funcReadDir,
 | 
			
		||||
		"listFiles":  stat.funcListFiles,
 | 
			
		||||
		"writeFile":  stat.funcWriteFile,
 | 
			
		||||
		"appendFile": stat.funcAppendFile,
 | 
			
		||||
		"renameFile": stat.funcRenameFile,
 | 
			
		||||
@ -92,6 +93,18 @@ func (this *state) funcReadDir (name string) ([]fs.DirEntry, error) {
 | 
			
		||||
	return os.ReadDir(name)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *state) funcListFiles (name string) ([]string, error) {
 | 
			
		||||
	name, err := this.document.Rel(name)
 | 
			
		||||
	if err != nil { return nil, err }
 | 
			
		||||
	entries, err := os.ReadDir(name)
 | 
			
		||||
	if err != nil { return nil, err }
 | 
			
		||||
	strings := make([]string, len(entries))
 | 
			
		||||
	for index, entry := range entries {
 | 
			
		||||
		strings[index] = entry.Name()
 | 
			
		||||
	}
 | 
			
		||||
	return strings, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *state) funcWriteFile (name, content string) error {
 | 
			
		||||
	name, err := this.document.Rel(name)
 | 
			
		||||
	if err != nil { return err }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user