Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
[GH-20] ensure that key starts with a dot
Browse files Browse the repository at this point in the history
  • Loading branch information
030 committed Nov 13, 2018
1 parent 21272dc commit 26a6889
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
func yamlValue(file string, key string) string {
viper.SetConfigType("yaml")

verifyKey(key)
keyWithoutFirstDot := strings.Replace(key, ".", "", 1)

filename := filename(file)
Expand Down Expand Up @@ -41,6 +42,12 @@ func filename(path string) string {
return filepath.Base(filename)
}

func verifyKey(key string) {
if !strings.HasPrefix(key, ".") {
log.Fatal("Key should start with a dot, i.e.: ."+key+", but was: ", key)
}
}

func main() {
if len(os.Args) <= 2 {
log.Fatal("Usage: go-yq <key e.g. .foo.bar> <filename e.g. input.yaml>")
Expand Down

0 comments on commit 26a6889

Please sign in to comment.