v / cmd / tools / measure / file_lists / expand.v
29 lines · 27 sloc · 773 bytes · c92577e6ed8278a219de7dd65fde65afd01bda4d
Raw
1module file_lists
2
3import os
4
5// expand_files accepts a list of files and folders, and returns a list of all the .v and .vsh files, found in them.
6// The input list of files, supports recursive `@file.lst` expansion, where each line is treated as another file/folder.
7pub fn expand_files(files []string) ![]string {
8 mut res := []string{}
9 for file in files {
10 if file == '' {
11 continue
12 }
13 if file.starts_with('@') {
14 lst_path := files[0].all_after('@').trim_space()
15 listed_files := os.read_file(lst_path)!.split('\n').map(it.trim_space())
16 res << expand_files(listed_files)!
17 continue
18 }
19 if os.is_dir(file) {
20 res << os.walk_ext(file, '.vsh')
21 res << os.walk_ext(file, '.v')
22 continue
23 }
24 if os.exists(file) {
25 res << file
26 }
27 }
28 return res
29}
30