Files
fb8fa2b0fe [COMPLIANCE] Add/Update Copyright Headers (#13699)
* [COMPLIANCE] Add/Update Copyright Headers

* make generate update

* make generate

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: sanya <[email protected]>
Co-authored-by: Sanya <[email protected]>
2026-09-15 17:10:54 +05:30

38 lines
641 B
Go

// Copyright IBM Corp. 2024, 2026
// SPDX-License-Identifier: BUSL-1.1
package kvflag
import (
"encoding/json"
"fmt"
"os"
)
// FlagJSON is a flag.Value implementation for parsing user variables
// from the command-line using JSON files.
type FlagJSON map[string]string
func (v *FlagJSON) String() string {
return ""
}
func (v *FlagJSON) Set(raw string) error {
f, err := os.Open(raw)
if err != nil {
return err
}
defer f.Close()
if *v == nil {
*v = make(map[string]string)
}
if err := json.NewDecoder(f).Decode(v); err != nil {
return fmt.Errorf(
"Error reading variables in '%s': %s", raw, err)
}
return nil
}