-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (38 loc) · 1.03 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
package main
import (
"flag"
"fmt"
"os"
"git.netflux.io/rob/envfilesubst/scanner"
)
const version = "0.1"
func main() {
var (
path string
printVersion bool
)
flag.StringVar(&path, "f", "", "The envfile to read from")
flag.BoolVar(&printVersion, "version", false, "Print version and exit")
flag.Parse()
if printVersion {
fmt.Fprintf(os.Stderr, "envfilesubst version %s\n", version)
os.Exit(0)
}
if path == "" {
fmt.Fprint(os.Stderr, "envfilesubst reads an input from stdin and pipes it to stdout, replacing $ENV_VAR or ${ENV_VAR} occurrences that can be found in the provided envfile.\n\n")
fmt.Fprint(os.Stderr, "Variables that cannot be found in envfile are left unchanged.\n\n")
fmt.Fprint(os.Stderr, "Usage:\n")
flag.PrintDefaults()
os.Exit(1)
}
envfile, err := os.Open(path)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v", err)
os.Exit(1)
}
scanner := scanner.New(os.Stdout, os.Stdin, envfile)
if err := scanner.Scan(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v", err)
os.Exit(1)
}
}