-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
40 lines (32 loc) · 984 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"bytes"
"fmt"
"log"
"os"
"strings"
"github.com/mitchellh/colorstring"
"golang.org/x/crypto/ssh/terminal"
"gopkg.in/alecthomas/kingpin.v2"
"gopkg.in/yaml.v2"
)
var (
varPrefix = kingpin.Flag("prefix", "credhub path prefix for vars").Short('p').Default("/concourse/main").String()
inputFile = kingpin.Flag("vars-file", "Pipeline vars file").Short('f').Required().File()
)
func main() {
kingpin.Parse()
var b bytes.Buffer
encoder := yaml.NewEncoder(&b)
if bulkImport, err := Transform(*varPrefix, *inputFile); err != nil {
log.Fatal(err)
} else {
encoder.Encode(bulkImport)
outStr := b.String()
fmt.Println(strings.Replace(outStr, "subMapValue", "value", -1))
// taken from https://rosettacode.org/wiki/Check_output_device_is_a_terminal#Go
if terminal.IsTerminal(int(os.Stdout.Fd())) {
colorstring.Println("[bold][green]Done! Double check these results, then save and run [reset]credhub import --file /path/to/file")
}
}
}