@@ -42,17 +42,41 @@ func templCSSSort(flags Flags) {
42
42
// find all .templ files in directory and subdirectories
43
43
var files []string
44
44
var err error
45
- if flags .file == "" {
46
- files , err = filepath .Glob ("./templates/*.templ" )
45
+ if flags .file != "" {
46
+ // If the file flag is specified, only take in that file
47
+ if ! strings .HasSuffix (flags .file , ".templ" ) {
48
+ log .Fatal ("File must have .templ extension" )
49
+ }
50
+ files = append (files , flags .file )
47
51
} else if flags .dir != "" {
48
- files , err = filepath .Glob (flags .dir + "/*.templ" )
52
+ // If the dir flag is specified, take in that dir and its subdirectories
53
+ err = filepath .Walk (flags .dir , func (path string , info os.FileInfo , err error ) error {
54
+ if err != nil {
55
+ return err
56
+ }
57
+ if ! info .IsDir () && strings .HasSuffix (info .Name (), ".templ" ) {
58
+ files = append (files , path )
59
+ }
60
+ return nil
61
+ })
49
62
} else {
50
- files = []string {flags .file }
63
+ // If neither flag is specified, go through cwd and all subdirectories for any .templ file
64
+ err = filepath .Walk ("." , func (path string , info os.FileInfo , err error ) error {
65
+ if err != nil {
66
+ return err
67
+ }
68
+ if ! info .IsDir () && strings .HasSuffix (info .Name (), ".templ" ) {
69
+ files = append (files , path )
70
+ }
71
+ return nil
72
+ })
51
73
}
52
74
if err != nil {
53
75
log .Fatal (err )
54
76
}
55
77
78
+ log .Println ("Found" , len (files ), "files" )
79
+
56
80
// parse each file
57
81
for _ , file := range files {
58
82
// read file
0 commit comments