summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/parse.go b/parse.go
index 1416223..3c682f5 100644
--- a/parse.go
+++ b/parse.go
@@ -2,6 +2,7 @@ package arg
import (
"encoding"
+ "encoding/csv"
"errors"
"fmt"
"os"
@@ -275,9 +276,28 @@ func process(specs []*spec, args []string) error {
}
if spec.env != "" {
if value, found := os.LookupEnv(spec.env); found {
- err := scalar.ParseValue(spec.dest, value)
- if err != nil {
- return fmt.Errorf("error processing environment variable %s: %v", spec.env, err)
+ if spec.multiple {
+ // expect a CSV string in an environment
+ // variable in the case of multiple values
+ values, err := csv.NewReader(strings.NewReader(value)).Read()
+ if err != nil {
+ return fmt.Errorf(
+ "error reading a CSV string from environment variable %s with multiple values: %v",
+ spec.env,
+ err,
+ )
+ }
+ if err = setSlice(spec.dest, values, !spec.separate); err != nil {
+ return fmt.Errorf(
+ "error processing environment variable %s with multiple values: %v",
+ spec.env,
+ err,
+ )
+ }
+ } else {
+ if err := scalar.ParseValue(spec.dest, value); err != nil {
+ return fmt.Errorf("error processing environment variable %s: %v", spec.env, err)
+ }
}
spec.wasPresent = true
}