Skip to content

Commit c27fdc7

Browse files
committed
feat: support the .yaml ext for flow files
1 parent adf7f7c commit c27fdc7

5 files changed

Lines changed: 39 additions & 6 deletions

File tree

internal/filesystem/executables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func findFlowFiles(logger io.Logger, workspaceCfg *workspace.Workspace) ([]strin
116116
return filepath.SkipDir
117117
}
118118

119-
if filepath.Ext(entry.Name()) == executable.FlowFileExt {
119+
if executable.HasFlowFileExt(entry.Name()) {
120120
cfgPaths = append(cfgPaths, path)
121121
}
122122
}

internal/templates/templates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func ProcessTemplate(
3636
flowfileName = fmt.Sprintf("executables_%s", time.Now().Format("20060102150405"))
3737
}
3838
flowfileName = strings.ReplaceAll(strings.ToLower(flowfileName), " ", "_")
39-
if !strings.HasSuffix(flowfileName, executable.FlowFileExt) {
39+
if !executable.HasFlowFileExt(flowfileName) {
4040
flowfileName += executable.FlowFileExt
4141
}
4242

types/executable/executables_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,22 @@ var _ = Describe("ExecutableList", func() {
309309
})
310310
})
311311
})
312+
313+
var _ = DescribeTable("HasFlowFileExt", func(file string, expected bool) {
314+
Expect(executable.HasFlowFileExt(file)).To(Equal(expected))
315+
},
316+
Entry("ends with .flow", "development.flow", true),
317+
Entry("ends with .flow.yaml", "development.flow.yaml", true),
318+
Entry("ends with .flow.yml", "development.flow.yml", true),
319+
Entry("ends with something else", "development.txt", false),
320+
)
321+
322+
var _ = DescribeTable("HasFlowFileTemplateExt", func(file string, expected bool) {
323+
Expect(executable.HasFlowFileTemplateExt(file)).To(Equal(expected))
324+
},
325+
Entry("ends with .flow.tmpl", "development.flow.tmpl", true),
326+
Entry("ends with .flow.tmpl.yaml", "development.flow.tmpl.yaml", true),
327+
Entry("ends with .flow.tmpl.yml", "development.flow.tmpl.yml", true),
328+
Entry("ends with .flow", "development.flow", false),
329+
Entry("ends with something else", "development.flow.txt", false),
330+
)

types/executable/flowfile.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package executable
22

33
import (
44
"fmt"
5+
"regexp"
56

67
"gopkg.in/yaml.v3"
78

@@ -12,6 +13,8 @@ import (
1213

1314
const FlowFileExt = ".flow"
1415

16+
var FlowFileExtRegex = regexp.MustCompile(fmt.Sprintf(`%s(\.yaml|\.yml)?`, regexp.QuoteMeta(FlowFileExt)))
17+
1518
type FlowFileList []*FlowFile
1619

1720
func (f *FlowFile) SetContext(workspaceName, workspacePath, configPath string) {
@@ -72,3 +75,7 @@ func (l *FlowFileList) FilterByTag(tag string) FlowFileList {
7275
}
7376
return filteredCfgs
7477
}
78+
79+
func HasFlowFileExt(file string) bool {
80+
return FlowFileExtRegex.MatchString(file)
81+
}

types/executable/template.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"path/filepath"
8+
"regexp"
89
"strings"
910

1011
"github.com/flowexec/tuikit/types"
@@ -15,6 +16,8 @@ import (
1516

1617
const FlowFileTemplateExt = ".flow.tmpl"
1718

19+
var FlowFileTemplateExtRegex = regexp.MustCompile(fmt.Sprintf(`%s(\.yaml|\.yml)?`, regexp.QuoteMeta(FlowFileTemplateExt)))
20+
1821
type TemplateList []*Template
1922

2023
func (f *Field) Set(value string) {
@@ -75,10 +78,10 @@ func (t *Template) SetContext(name, location string) {
7578
if name == "" {
7679
fn := filepath.Base(location)
7780
switch {
78-
case strings.HasSuffix(fn, FlowFileTemplateExt):
79-
fn = strings.TrimSuffix(fn, FlowFileTemplateExt)
80-
case strings.HasSuffix(fn, FlowFileExt):
81-
fn = strings.TrimSuffix(fn, FlowFileExt)
81+
case HasFlowFileTemplateExt(fn):
82+
fn, _, _ = strings.Cut(fn, FlowFileTemplateExt)
83+
case HasFlowFileExt(fn):
84+
fn, _, _ = strings.Cut(fn, FlowFileExt)
8285
default:
8386
fn = strings.TrimSuffix(fn, filepath.Ext(fn))
8487
}
@@ -164,3 +167,7 @@ func (t TemplateList) Find(name string) *Template {
164167
}
165168
return nil
166169
}
170+
171+
func HasFlowFileTemplateExt(file string) bool {
172+
return FlowFileTemplateExtRegex.MatchString(file)
173+
}

0 commit comments

Comments
 (0)