Skip to content

Commit

Permalink
fix: add error handeling for kvtj command (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradumnasaraf authored Jun 7, 2023
1 parent 6cf1b3f commit c1c27b4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cmd/keyValueToJson.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,22 @@ var keyValueToJson = &cobra.Command{
entries := strings.Split(string(content), "\n")
m := make(map[string]string)
for _, e := range entries {

// Skip empty lines, comments and lines without "="
if e == "" {
continue
}

if strings.HasPrefix(e, "#") || strings.HasPrefix(e, "//") {
continue
}

if !strings.Contains(e, "=") {
continue
}

parts := strings.Split(e, "=")
m[parts[0]] = parts[1]
m[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
}
jsonString, _ := json.MarshalIndent(m, "", " ")

Expand Down

0 comments on commit c1c27b4

Please sign in to comment.