Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from sampointer/multiple_directories_documents
Browse files Browse the repository at this point in the history
Support multiple directory arguments.
  • Loading branch information
sampointer authored Apr 3, 2020
2 parents a695e09 + f551539 commit 5c69fbc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ $ dy k8s_deployment/ | kubectl apply --validate=true --dry-run=true -f -
deployment.apps/nginx-deployment created (dry run)
```

You may pass multiple directories as arguments and they will each be parsed and
emitted as documents in their own right. In this way a single `dy` invocation
can be used to produce a valid YAML stream.

## Installing
### Homebrew
```
Expand Down
30 changes: 23 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,34 @@ import (

func main() {
var dy divvy.DivvyYaml
var multiDoc bool

// Do the most basic argument parsing possible
if len(os.Args) < 2 {
os.Stderr.WriteString("you must pass a path as an argument\n")
os.Stderr.WriteString("you must pass at least one path as an argument\n")
os.Exit(1)
}

err := dy.Parse(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(2)
} else {
fmt.Println(dy.Doc)
if len(os.Args) > 2 {
multiDoc = true
}

// Allow multiple arguments and emit each as a different document
for i, dir := range os.Args {
if i == 0 {
continue
}

err := dy.Parse(dir)

if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(2)
} else {
if multiDoc == true {
fmt.Println("---")
}
fmt.Println(dy.Doc)
}
}
}

0 comments on commit 5c69fbc

Please sign in to comment.