Skip to content

Commit 2975216

Browse files
Merge pull request #9 from actionforge/dir-create
Add core/dir-create@v1
2 parents 5626d32 + 76c596b commit 2975216

3 files changed

Lines changed: 114 additions & 0 deletions

File tree

node_interfaces/interface_core_dir-create_v1.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodes/dir-create@v1.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package nodes
2+
3+
import (
4+
_ "embed"
5+
"os"
6+
7+
"github.com/actionforge/actrun-cli/core"
8+
ni "github.com/actionforge/actrun-cli/node_interfaces"
9+
)
10+
11+
//go:embed dir-create@v1.yml
12+
var dirCreateDefinition string
13+
14+
type DirCreateNode struct {
15+
core.NodeBaseComponent
16+
core.Executions
17+
core.Inputs
18+
core.Outputs
19+
}
20+
21+
func (n *DirCreateNode) ExecuteImpl(c *core.ExecutionState, inputId core.InputId, prevError error) error {
22+
path, err := core.InputValueById[string](c, n, ni.Core_dir_create_v1_Input_path)
23+
if err != nil {
24+
return err
25+
}
26+
27+
mkdirAll, err := core.InputValueById[bool](c, n, ni.Core_dir_create_v1_Input_create_parents)
28+
if err != nil {
29+
return err
30+
}
31+
32+
var mkdirErr error
33+
if mkdirAll {
34+
mkdirErr = os.MkdirAll(path, 0755)
35+
} else {
36+
mkdirErr = os.Mkdir(path, 0755)
37+
}
38+
39+
if mkdirErr != nil {
40+
err := core.CreateErr(c, mkdirErr, "failed to create directory")
41+
return n.Execute(ni.Core_dir_create_v1_Output_exec_err, c, err)
42+
}
43+
44+
return n.Execute(ni.Core_dir_create_v1_Output_exec_success, c, nil)
45+
}
46+
47+
func init() {
48+
err := core.RegisterNodeFactory(dirCreateDefinition, func(ctx any, parent core.NodeBaseInterface, parentId string, nodeDef map[string]any, validate bool) (core.NodeBaseInterface, []error) {
49+
return &DirCreateNode{}, nil
50+
})
51+
if err != nil {
52+
panic(err)
53+
}
54+
}

nodes/dir-create@v1.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
yaml-version: 3.0
2+
3+
id: core/dir-create
4+
name: Dir Create
5+
version: 1
6+
icon: tablerFolderPlus
7+
category: filesystem
8+
short_desc: Create a directory on the file system.
9+
style:
10+
header:
11+
background: rgb(197, 147, 31)
12+
body:
13+
background: "rgb(164 115 29)"
14+
inputs:
15+
exec:
16+
exec: true
17+
index: 0
18+
path:
19+
name: Path
20+
type: string
21+
index: 1
22+
required: true
23+
desc: The path of the directory to create.
24+
create_parents:
25+
name: Create Parents
26+
type: bool
27+
index: 2
28+
default: true
29+
desc: If true, creates all parent directories as needed (like mkdir -p). If false, only creates the final directory and fails if parent directories don't exist.
30+
outputs:
31+
exec-success:
32+
name: Success
33+
exec: true
34+
index: 0
35+
desc: Executes if the directory creation is successful.
36+
exec-err:
37+
name: Error
38+
exec: true
39+
index: 1
40+
desc: Executes if the directory creation fails.

0 commit comments

Comments
 (0)