Skip to content

Commit 303df49

Browse files
committed
feat: add file-based helper funcs to the expression language
1 parent 1cd96ea commit 303df49

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

docs/guide/advanced.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The expression language supports standard comparison and logical operators:
1616
- String: `+` (concatenation), `matches` (regex matching)
1717
- Length: `len()`
1818

19-
See the [Expr Language Definition](https://expr-lang.org/docs/language-definition) for all available operators and functions.
19+
**See the [Expr Language Definition](https://expr-lang.org/docs/language-definition) for all available operators and functions.**
2020

2121
### Basic Conditions <!-- {docsify-ignore} -->
2222

@@ -63,6 +63,27 @@ executables:
6363
cmd: npm test
6464
```
6565
66+
### File System Conditions <!-- {docsify-ignore} -->
67+
Check for files or directories to control execution:
68+
69+
```yaml
70+
executables:
71+
- verb: deploy
72+
name: app
73+
serial:
74+
execs:
75+
# Only run if config file exists
76+
- if: fileExists("config.yaml")
77+
cmd: kubectl apply -f config.yaml
78+
79+
# Abort deployment if no Dockerfile found
80+
- if: not fileExists("Dockerfile")
81+
cmd: echo "No Dockerfile found"; exit 1
82+
83+
# Run deployment if Dockerfile exists
84+
- cmd: docker build -t myapp .
85+
```
86+
6687
### Data-Driven Conditions <!-- {docsify-ignore} -->
6788
6889
Use stored data to control execution flow:
@@ -106,6 +127,19 @@ Conditions have access to extensive runtime information:
106127
- `ctx.flowFilePath` - Path to current flow file
107128
- `ctx.flowFileDir` - Directory containing current flow file
108129

130+
Additionally the following functions are provided alongside the Expr language definition:
131+
132+
- `fileExists(path)` - Check if file/directory exists
133+
- `dirExists(path)` - Check if path is a directory
134+
- `isFile(path)` - Check if path is a file
135+
- `isDir(path)` - Check if path is a directory
136+
- `basename(path)` - Get filename from path
137+
- `dirname(path)` - Get directory from path
138+
- `readFile(path)` - Read file contents as string
139+
- `fileSize(path)` - Get file size in bytes
140+
- `fileModTime(path)` - Get file modification time
141+
- `fileAge(path)` - Get duration since last modified
142+
109143
## Managing State
110144

111145
Persist data across executions and share information between workflow steps.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/flowexec/tuikit v0.2.3
1212
github.com/flowexec/vault v0.2.1
1313
github.com/gen2brain/beeep v0.11.1
14-
github.com/jahvon/expression v0.1.3
14+
github.com/jahvon/expression v0.1.4
1515
github.com/jahvon/glamour v0.8.1-patch3
1616
github.com/mark3labs/mcp-go v0.37.0
1717
github.com/mattn/go-runewidth v0.0.16

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcI
118118
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
119119
github.com/jackmordaunt/icns/v3 v3.0.1 h1:xxot6aNuGrU+lNgxz5I5H0qSeCjNKp8uTXB1j8D4S3o=
120120
github.com/jackmordaunt/icns/v3 v3.0.1/go.mod h1:5sHL59nqTd2ynTnowxB/MDQFhKNqkK8X687uKNygaSQ=
121-
github.com/jahvon/expression v0.1.3 h1:ZOH6tj1zK9h+M+eDy/n1Fz6XL/vA3lCV6bzHe6YWAvY=
122-
github.com/jahvon/expression v0.1.3/go.mod h1:4HJB2k+epW5vFeptF6ILlXbFRQ+CuCyCSO4QdnGT3AE=
121+
github.com/jahvon/expression v0.1.4 h1:4q/jvM5G2mBJDqXtTUDThtJ4Sfajx+vIhUf4r6EAy6A=
122+
github.com/jahvon/expression v0.1.4/go.mod h1:4HJB2k+epW5vFeptF6ILlXbFRQ+CuCyCSO4QdnGT3AE=
123123
github.com/jahvon/glamour v0.8.1-patch3 h1:LfyMACZavV8yxK4UsPENNQQOqafWuq4ZdLuEAP2ZLE8=
124124
github.com/jahvon/glamour v0.8.1-patch3/go.mod h1:30MVJwG3rcEHrN277NrA4DKzndSL9lBtEmpcfOygwCQ=
125125
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=

0 commit comments

Comments
 (0)