Skip to content

Simple cli to concatenate yaml files to stdout

License

Notifications You must be signed in to change notification settings

doddle/yaml-concat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Usage

This tool will:

  • walk a --path of files looking for *.yaml and *.yml files
  • on default hidden files (eg .hidden.yaml will be ignored (#TODO: allow searching for them also, or a custom exclude list?)
  • for each yaml file found it will stream each individual document to stdout

Notes:

  • This handles individual documents inside a file (--- seperated docs in a files) consistently
  • yaml is produced to stdout, all logging/comments/status as this script runs is sent to stderr (although error logging/panicing has not been reviewed yet)
  • comments and quoting are preserved, sometimes this can come out "weird"

yaml-concat --path ./source/files/

Issues

  1. there are no test! (yet)
  2. Potential for empty --- documents
  3. about 10 minutes has been spent assessing the logging behaviour, it needs work
  4. no effort has been put into the guarantees around executing this.

Sources

Reasoning:

  1. I need to safely stream files from a folder into stdout (and exclude certain ones)
  2. python's vanilla pyyaml is a nightmare (doesn't care about quotes and goes on to even wreck types and then also their values..) (EG: foo: '00123' can become: foo: 123 ..danger Will Robinson!)

example:

input file: "sample.yaml"

raw content looks like:

apiVersion: acme/v1
kind: Deployment
spec:
  replicas: 3
  template:
    spec:
      containers:
      # much myimage, so wow
      - image: myimage:foo-bar
        name: someapp
        ports:
          - containerPort: 8080
            name: http
        env:
        - name: SOME_VAR
          value: '00123123'

output:

# source: ./sample.yaml[0]
apiVersion: acme/v1
kind: Deployment
spec:
  replicas: 3
  template:
    spec:
      containers:
      # much myimage, so wow
      - image: myimage:foo-bar
        name: someapp
        ports:
        - containerPort: 8080
          name: http
        env:
        - name: SOME_VAR
          value: '00123123'
---
# source: ./sample.yaml[1]
anotherDoc: true
handled: "just fine"

About

Simple cli to concatenate yaml files to stdout

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages