forked from jontours/vars-to-credhub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (37 loc) · 1.11 KB
/
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
41
42
43
44
45
46
47
48
49
package main
import (
"bytes"
"fmt"
"log"
"os"
"github.com/mitchellh/colorstring"
"golang.org/x/crypto/ssh/terminal"
"gopkg.in/alecthomas/kingpin.v2"
"gopkg.in/yaml.v2"
)
// Version the program version number
var Version = "(development)"
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() {
var app = kingpin.Version(Version)
app.VersionFlag.Short('v')
app.HelpFlag.Short('h')
kingpin.Parse()
var out bytes.Buffer
encoder := yaml.NewEncoder(&out)
if bulkImport, err := Transform(*varPrefix, *inputFile); err != nil {
log.Fatal(err)
os.Exit(1)
} else if err := encoder.Encode(bulkImport); err != nil {
log.Fatal(err)
os.Exit(1)
}
fmt.Print(out.String())
// 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")
}
}