Skip to content

Commit

Permalink
feat: make specs executable
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Mar 26, 2023
1 parent aa0f140 commit b28049f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ paths:
description: OK
```
## Executable Specs
You can make you spec an executable program, add the following line:
```yaml
#!/usr/bin/env sim
```

Make your YAML executable with `chmod +x`.

## Reference

In you script you have access to the following:
Expand Down
1 change: 1 addition & 0 deletions examples/hello.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env sim
openapi: 3.0.0
info:
title: Hello API 2
Expand Down
1 change: 1 addition & 0 deletions examples/scripting.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env sim
openapi: 3.0.0
info:
title: Teapot API
Expand Down
1 change: 1 addition & 0 deletions examples/state.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env sim
openapi: 3.0.0
info:
title: Document API
Expand Down
22 changes: 16 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,25 @@ func main() {
if err := watcher.Add(path); err != nil {
log.Fatalf("Error watching directory: %s\n", err)
}
dir, err := os.ReadDir(path)
stat, err := os.Stat(path)
if err != nil {
log.Fatalf("Error reading directory: %s\n", err)
log.Fatal(err)
}
for _, file := range dir {
if filepath.Ext(file.Name()) != ".yaml" {
continue
if stat.IsDir() {
dir, err := os.ReadDir(path)
if err != nil {
log.Fatalf("Error reading directory: %s\n", err)
}
if err := sim.add(filepath.Join(path, file.Name())); err != nil {
for _, file := range dir {
if filepath.Ext(file.Name()) != ".yaml" {
continue
}
if err := sim.add(filepath.Join(path, file.Name())); err != nil {
log.Fatalf("Error adding spec: %s\n", err)
}
}
} else {
if err := sim.add(path); err != nil {
log.Fatalf("Error adding spec: %s\n", err)
}
}
Expand Down

0 comments on commit b28049f

Please sign in to comment.