Created
October 20, 2014 05:28
-
-
Save rochacon/5cf61b18bf789f87ab08 to your computer and use it in GitHub Desktop.
Simple script to list Procfile entries from a tar stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Read and parse an Procfile of a tar stream from stdin | |
// | |
// example: git archive HEAD | list-app-processes | |
// | |
// | |
package main | |
import ( | |
"archive/tar" | |
"fmt" | |
"gopkg.in/yaml.v1" | |
"io" | |
"io/ioutil" | |
"log" | |
"os" | |
) | |
type Processes map[string]string | |
func main() { | |
tarfile := tar.NewReader(os.Stdin) | |
for { | |
header, err := tarfile.Next() | |
if err == io.EOF { | |
break | |
} | |
if err != nil { | |
log.Fatal(err) | |
} | |
if header.Name == "Procfile" { | |
procfile, err := ioutil.ReadAll(tarfile) | |
if err != nil { | |
log.Fatal(err) | |
} | |
processes := Processes{} | |
err = yaml.Unmarshal(procfile, &processes) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for process, _ := range processes { | |
fmt.Println(process) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment