Skip to content

Commit e7ef96a

Browse files
authored
feat: add 'if' conditional processor to serial and parallel execs (#193)
1 parent 6c7084e commit e7ef96a

File tree

25 files changed

+781
-33
lines changed

25 files changed

+781
-33
lines changed

cmd/internal/store.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ import (
1616
func RegisterStoreCmd(ctx *context.Context, rootCmd *cobra.Command) {
1717
subCmd := &cobra.Command{
1818
Use: "store",
19-
Short: "Manage the data store.",
20-
Args: cobra.NoArgs,
19+
Short: "Manage the data store for persisting key-value data.",
20+
Long: "Manage the flow data store - a key-value store that persists data within and across executable runs. " +
21+
"Values set outside executables persist globally, while values set within executables persist only for " +
22+
"that execution scope.",
23+
Args: cobra.NoArgs,
2124
}
2225
registerStoreSetCmd(ctx, subCmd)
2326
registerStoreGetCmd(ctx, subCmd)
@@ -28,7 +31,7 @@ func RegisterStoreCmd(ctx *context.Context, rootCmd *cobra.Command) {
2831
func registerStoreSetCmd(ctx *context.Context, rootCmd *cobra.Command) {
2932
subCmd := &cobra.Command{
3033
Use: "set KEY [VALUE]",
31-
Short: "Set a key-value pair in the data store.",
34+
Short: "Set a key-value pair in the store.",
3235
Long: dataStoreDescription + "This will overwrite any existing value for the key.",
3336
Args: cobra.MinimumNArgs(1),
3437
Run: func(cmd *cobra.Command, args []string) {
@@ -89,7 +92,7 @@ func registerStoreGetCmd(ctx *context.Context, rootCmd *cobra.Command) {
8992
subCmd := &cobra.Command{
9093
Use: "get KEY",
9194
Aliases: []string{"view"},
92-
Short: "Get a value from the data store.",
95+
Short: "Get a value from the store by its key.",
9396
Long: dataStoreDescription + "This will retrieve the value for the given key.",
9497
Args: cobra.ExactArgs(1),
9598
Run: func(cmd *cobra.Command, args []string) {
@@ -125,7 +128,7 @@ func registerStoreClearCmd(ctx *context.Context, rootCmd *cobra.Command) {
125128
subCmd := &cobra.Command{
126129
Use: "clear",
127130
Aliases: []string{"reset"},
128-
Short: "Clear the data store.",
131+
Short: "Clear data from the store. Use --full to remove all stored data.",
129132
Long: dataStoreDescription + "This will remove all keys and values from the data store.",
130133
Args: cobra.NoArgs,
131134
Run: func(cmd *cobra.Command, args []string) {
@@ -142,7 +145,7 @@ func storeClearFunc(ctx *context.Context, cmd *cobra.Command, _ []string) {
142145
if err := store.DestroyStore(); err != nil {
143146
ctx.Logger.FatalErr(err)
144147
}
145-
ctx.Logger.PlainTextSuccess("Data store cleared")
148+
ctx.Logger.PlainTextSuccess("Store store cleared")
146149
return
147150
}
148151
s, err := store.NewStore()
@@ -157,7 +160,7 @@ func storeClearFunc(ctx *context.Context, cmd *cobra.Command, _ []string) {
157160
if err := s.DeleteBucket(store.EnvironmentBucket()); err != nil {
158161
ctx.Logger.FatalErr(err)
159162
}
160-
ctx.Logger.PlainTextSuccess("Data store cleared")
163+
ctx.Logger.PlainTextSuccess("Store store cleared")
161164
}
162165

163166
var dataStoreDescription = "The data store is a key-value store that can be used to persist data across executions. " +

docs/_sidebar.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- [Workspaces](guide/workspace.md "Managing workspaces")
1010
- [Executables](guide/executable.md "Managing executables")
1111
- [Templating](guide/templating.md "Using flowfile templates")
12+
- [Managing state](guide/state.md "Managing executable state")
13+
- [Conditional execution](guide/conditional.md "Conditional execution")
1214

1315
- Reference
1416

docs/cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ See github.com/jahvon/flow for more information.
2424
* [flow library](flow_library.md) - View and manage your library of workspaces and executables.
2525
* [flow logs](flow_logs.md) - List and view logs for previous flow executions.
2626
* [flow secret](flow_secret.md) - Manage flow secrets.
27-
* [flow store](flow_store.md) - Manage the data store.
27+
* [flow store](flow_store.md) - Manage the data store for persisting key-value data.
2828
* [flow sync](flow_sync.md) - Scan workspaces and update flow cache.
2929
* [flow template](flow_template.md) - Manage flowfile templates.
3030
* [flow workspace](flow_workspace.md) - Manage flow workspaces.

docs/cli/flow_store.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
## flow store
22

3-
Manage the data store.
3+
Manage the data store for persisting key-value data.
4+
5+
### Synopsis
6+
7+
Manage the flow data store - a key-value store that persists data within and across executable runs. Values set outside executables persist globally, while values set within executables persist only for that execution scope.
48

59
### Options
610

@@ -19,7 +23,7 @@ Manage the data store.
1923
### SEE ALSO
2024

2125
* [flow](flow.md) - flow is a command line interface designed to make managing and running development workflows easier.
22-
* [flow store clear](flow_store_clear.md) - Clear the data store.
23-
* [flow store get](flow_store_get.md) - Get a value from the data store.
24-
* [flow store set](flow_store_set.md) - Set a key-value pair in the data store.
26+
* [flow store clear](flow_store_clear.md) - Clear data from the store. Use --full to remove all stored data.
27+
* [flow store get](flow_store_get.md) - Get a value from the store by its key.
28+
* [flow store set](flow_store_set.md) - Set a key-value pair in the store.
2529

docs/cli/flow_store_clear.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## flow store clear
22

3-
Clear the data store.
3+
Clear data from the store. Use --full to remove all stored data.
44

55
### Synopsis
66

@@ -29,5 +29,5 @@ flow store clear [flags]
2929

3030
### SEE ALSO
3131

32-
* [flow store](flow_store.md) - Manage the data store.
32+
* [flow store](flow_store.md) - Manage the data store for persisting key-value data.
3333

docs/cli/flow_store_get.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## flow store get
22

3-
Get a value from the data store.
3+
Get a value from the store by its key.
44

55
### Synopsis
66

@@ -28,5 +28,5 @@ flow store get KEY [flags]
2828

2929
### SEE ALSO
3030

31-
* [flow store](flow_store.md) - Manage the data store.
31+
* [flow store](flow_store.md) - Manage the data store for persisting key-value data.
3232

docs/cli/flow_store_set.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## flow store set
22

3-
Set a key-value pair in the data store.
3+
Set a key-value pair in the store.
44

55
### Synopsis
66

@@ -28,5 +28,5 @@ flow store set KEY [VALUE] [flags]
2828

2929
### SEE ALSO
3030

31-
* [flow store](flow_store.md) - Manage the data store.
31+
* [flow store](flow_store.md) - Manage the data store for persisting key-value data.
3232

docs/guide/_sidebar.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
- [Workspaces](workspace.md "Managing workspaces")
99
- [Executables](executable.md "Managing executables")
1010
- [Templating](templating.md "Using flowfile templates")
11+
- [Managing state](guide/state.md "Managing executable state")
12+
- [Conditional execution](guide/conditional.md "Conditional execution")
13+

docs/guide/conditional.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Conditional Expressions
2+
3+
flow CLI uses conditional expressions to control [executable](executable.md) behavior based on runtime conditions. These expressions are written
4+
using a simple expression language that provides access to system information, environment variables, and stored data.
5+
6+
## Expression Language
7+
8+
Flow uses the [Expr](https://expr-lang.org) language for evaluating conditions. The language supports common
9+
operators and functions while providing access to flow executable-specific context data.
10+
11+
**See the [Expr language documentation](https://expr-lang.org/docs/language-definition) for more information on the
12+
expression syntax.**
13+
14+
### Basic Operators
15+
16+
The expression language supports standard comparison and logical operators:
17+
18+
- Comparison: `==`, `!=`, `<`, `>`, `<=`, `>=`
19+
- Logical: `and`, `or`, `not`
20+
- String: `+` (concatenation), `matches` (regex matching)
21+
- Length: `len()`
22+
23+
### Available Context
24+
25+
When writing conditions, you have access to several context variables:
26+
27+
- `os`: Operating system (e.g., "linux", "darwin", "windows")
28+
- `arch`: System architecture (e.g., "amd64", "arm64")
29+
- `ctx`: Flow context information
30+
- `workspace`: Current workspace name
31+
- `namespace`: Current namespace
32+
- `workspacePath`: Path to current workspace
33+
- `flowFilePath`: Path to current flow file
34+
- `flowFileDir`: Directory containing current flow file
35+
- `store`: Key-value map of data store contents
36+
- `env`: Map of environment variables
37+
38+
## Writing Conditions
39+
40+
Conditions can be used in various places within flow, most commonly in the `if` field of executable configurations. Here are
41+
some examples of common conditional patterns:
42+
43+
### Operating System and Architecture Checks
44+
45+
Check for specific operating systems or architectures:
46+
47+
```yaml
48+
executables:
49+
- verb: install
50+
name: system-specific
51+
serial:
52+
execs:
53+
- if: os == "darwin"
54+
cmd: brew install myapp
55+
- if: os == "linux"
56+
cmd: apt-get install myapp
57+
- if: arch == "amd64"
58+
cmd: make build-amd64
59+
- if: arch == "arm64"
60+
cmd: make build-arm64
61+
```
62+
63+
### Environment Variable Checks
64+
65+
Make decisions based on environment variables:
66+
67+
```yaml
68+
executables:
69+
- verb: deploy
70+
name: env-check
71+
serial:
72+
execs:
73+
- if: env["ENVIRONMENT"] == "production"
74+
cmd: echo "Deploying to production"
75+
- if: env["DEBUG"] == "true"
76+
cmd: echo "Debug mode enabled"
77+
```
78+
79+
### Data Store Conditions
80+
81+
Use stored data to control execution:
82+
83+
```yaml
84+
executables:
85+
- verb: run
86+
name: data-check
87+
serial:
88+
execs:
89+
- cmd: flow store set feature-flag enabled
90+
- if: data["feature-flag"] == "enabled"
91+
cmd: echo "Feature is enabled"
92+
- if: len(data["optional-key"]) > 0
93+
cmd: echo "Optional key exists"
94+
```
95+
96+
### Complex Conditions
97+
98+
Combine multiple conditions using logical operators:
99+
100+
```yaml
101+
executables:
102+
- verb: build
103+
name: complex-check
104+
serial:
105+
execs:
106+
- if: os == "linux" and env["CI"] == "true"
107+
cmd: echo "Running in Linux CI environment"
108+
- if: len(data["build-id"]) > 0 and (os == "darwin" or os == "linux")
109+
cmd: echo "Valid build on Unix-like system"
110+
```
111+
112+
### Path and Location Checks
113+
114+
Use context information to make path-based decisions:
115+
116+
```yaml
117+
executables:
118+
- verb: setup
119+
name: path-check
120+
serial:
121+
execs:
122+
- if: ctx.workspace == "development"
123+
cmd: echo "development workspace is active"
124+
- if: ctx.flowFileDir matches ".*/scripts$"
125+
cmd: echo "In scripts directory"
126+
```

0 commit comments

Comments
 (0)