summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorIllia Volochii <[email protected]>2018-05-01 12:02:44 +0300
committerIllia Volochii <[email protected]>2018-05-01 12:02:44 +0300
commitfa5fe315f85333e5e7dc0b2147cbe3aae3e4afce (patch)
treeb5c0c84d178952527b91d4ae8e654f1a5a0b8584 /parse.go
parent488fd7e82ab39ded1347fa792b4243efbc9d4239 (diff)
Change format from JSON to CSV
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go16
1 files changed, 5 insertions, 11 deletions
diff --git a/parse.go b/parse.go
index 03b6c07..1b534fd 100644
--- a/parse.go
+++ b/parse.go
@@ -2,7 +2,7 @@ package arg
import (
"encoding"
- "encoding/json"
+ "encoding/csv"
"errors"
"fmt"
"os"
@@ -278,18 +278,12 @@ func process(specs []*spec, args []string) error {
if value, found := os.LookupEnv(spec.env); found {
var err error
if spec.multiple {
- // expect a JSON array of strings in an environment
+ // expect a CSV string in an environment
// variable in the case of multiple values
- var values []string
- err = json.Unmarshal([]byte(value), &values)
- if err != nil {
- return fmt.Errorf(
- "error processing environment variable %s (it should be a JSON array of strings):\n%v",
- spec.env,
- err,
- )
+ values, err := csv.NewReader(strings.NewReader(value)).Read()
+ if err == nil {
+ err = setSlice(spec.dest, values, !spec.separate)
}
- err = setSlice(spec.dest, values, !spec.separate)
} else {
err = scalar.ParseValue(spec.dest, value)
}