diff options
Diffstat (limited to 'forged/internal/common/scfg')
| -rw-r--r-- | forged/internal/common/scfg/reader.go | 3 | ||||
| -rw-r--r-- | forged/internal/common/scfg/scfg.go | 7 | ||||
| -rw-r--r-- | forged/internal/common/scfg/struct.go | 17 | ||||
| -rw-r--r-- | forged/internal/common/scfg/unmarshal.go | 16 | ||||
| -rw-r--r-- | forged/internal/common/scfg/writer.go | 5 |
5 files changed, 26 insertions, 22 deletions
diff --git a/forged/internal/common/scfg/reader.go b/forged/internal/common/scfg/reader.go index b0e2cc0..3ec45e4 100644 --- a/forged/internal/common/scfg/reader.go +++ b/forged/internal/common/scfg/reader.go @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: Copyright (c) 2020 Simon Ser <https://emersion.fr> +// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> -package scfg +package scfgs import ( "bufio" diff --git a/forged/internal/common/scfg/scfg.go b/forged/internal/common/scfg/scfg.go index 4533e63..3128b1c 100644 --- a/forged/internal/common/scfg/scfg.go +++ b/forged/internal/common/scfg/scfg.go @@ -1,9 +1,10 @@ // SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: Copyright (c) 2020 Simon Ser <https://emersion.fr> +// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> -// Package scfg parses and formats configuration files. -// Note that this fork of scfg behaves differently from upstream scfg. -package scfg +// Package scfgs parses and formats configuration files. +// Note that this fork of scfgs behaves differently from upstream scfg. +package scfgs import ( "fmt" diff --git a/forged/internal/common/scfg/struct.go b/forged/internal/common/scfg/struct.go index 98ec943..c222385 100644 --- a/forged/internal/common/scfg/struct.go +++ b/forged/internal/common/scfg/struct.go @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: Copyright (c) 2020 Simon Ser <https://emersion.fr> +// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> -package scfg +package scfgs import ( "fmt" @@ -10,7 +11,7 @@ import ( "sync" ) -// structInfo contains scfg metadata for structs. +// structInfo contains scfgs metadata for structs. type structInfo struct { param int // index of field storing parameters children map[string]int // indices of fields storing child directives @@ -37,12 +38,12 @@ func getStructInfo(t reflect.Type) (*structInfo, error) { for i := 0; i < t.NumField(); i++ { f := t.Field(i) if f.Anonymous { - return nil, fmt.Errorf("scfg: anonymous struct fields are not supported") + return nil, fmt.Errorf("scfgs: anonymous struct fields are not supported") } else if !f.IsExported() { continue } - tag := f.Tag.Get("scfg") + tag := f.Tag.Get("scfgs") parts := strings.Split(tag, ",") k, options := parts[0], parts[1:] if k == "-" { @@ -57,21 +58,21 @@ func getStructInfo(t reflect.Type) (*structInfo, error) { case "param": isParam = true default: - return nil, fmt.Errorf("scfg: invalid option %q in struct tag", opt) + return nil, fmt.Errorf("scfgs: invalid option %q in struct tag", opt) } } if isParam { if info.param >= 0 { - return nil, fmt.Errorf("scfg: param option specified multiple times in struct tag in %v", t) + return nil, fmt.Errorf("scfgs: param option specified multiple times in struct tag in %v", t) } if parts[0] != "" { - return nil, fmt.Errorf("scfg: name must be empty when param option is specified in struct tag in %v", t) + return nil, fmt.Errorf("scfgs: name must be empty when param option is specified in struct tag in %v", t) } info.param = i } else { if _, ok := info.children[k]; ok { - return nil, fmt.Errorf("scfg: key %q specified multiple times in struct tag in %v", k, t) + return nil, fmt.Errorf("scfgs: key %q specified multiple times in struct tag in %v", k, t) } info.children[k] = i } diff --git a/forged/internal/common/scfg/unmarshal.go b/forged/internal/common/scfg/unmarshal.go index 8befc10..e60bcc7 100644 --- a/forged/internal/common/scfg/unmarshal.go +++ b/forged/internal/common/scfg/unmarshal.go @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 Simon Ser <https://emersion.fr> // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> -package scfg +package scfgs import ( "encoding" @@ -12,7 +12,7 @@ import ( "strconv" ) -// Decoder reads and decodes an scfg document from an input stream. +// Decoder reads and decodes an scfgs document from an input stream. type Decoder struct { r io.Reader unknownDirectives []*Directive @@ -29,7 +29,7 @@ func (dec *Decoder) UnknownDirectives() []*Directive { return dec.unknownDirectives } -// Decode reads scfg document from the input and stores it in the value pointed +// Decode reads scfgs document from the input and stores it in the value pointed // to by v. // // If v is nil or not a pointer, Decode returns an error. @@ -60,7 +60,7 @@ func (dec *Decoder) UnknownDirectives() []*Directive { // unmarshaled into the value. Children blocks are not allowed. // // The decoding of each struct field can be customized by the format string -// stored under the "scfg" key in the struct field's tag. The tag contains the +// stored under the "scfgs" key in the struct field's tag. The tag contains the // name of the field possibly followed by a comma-separated list of options. // The name may be empty in order to specify options without overriding the // default field name. As a special case, if the field name is "-", the field @@ -74,7 +74,7 @@ func (dec *Decoder) Decode(v interface{}) error { rv := reflect.ValueOf(v) if rv.Kind() != reflect.Ptr || rv.IsNil() { - return fmt.Errorf("scfg: invalid value for unmarshaling") + return fmt.Errorf("scfgs: invalid value for unmarshaling") } return dec.unmarshalBlock(block, rv) @@ -92,7 +92,7 @@ func (dec *Decoder) unmarshalBlock(block Block, v reflect.Value) error { switch v.Kind() { case reflect.Map: if t.Key().Kind() != reflect.String { - return fmt.Errorf("scfg: map key type must be string") + return fmt.Errorf("scfgs: map key type must be string") } if v.IsNil() { v.Set(reflect.MakeMap(t)) @@ -134,12 +134,12 @@ func (dec *Decoder) unmarshalBlock(block Block, v reflect.Value) error { continue } if _, ok := seen[fieldIndex]; !ok { - return fmt.Errorf("scfg: missing required directive %q", name) + return fmt.Errorf("scfgs: missing required directive %q", name) } } default: - return fmt.Errorf("scfg: unsupported type for unmarshaling blocks: %v", t) + return fmt.Errorf("scfgs: unsupported type for unmarshaling blocks: %v", t) } return nil diff --git a/forged/internal/common/scfg/writer.go b/forged/internal/common/scfg/writer.go index 02a07fe..979d71f 100644 --- a/forged/internal/common/scfg/writer.go +++ b/forged/internal/common/scfg/writer.go @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: Copyright (c) 2020 Simon Ser <https://emersion.fr> +// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> -package scfg +package scfgs import ( "errors" @@ -9,7 +10,7 @@ import ( "strings" ) -var errDirEmptyName = errors.New("scfg: directive with empty name") +var errDirEmptyName = errors.New("scfgs: directive with empty name") // Write writes a parsed configuration to the provided io.Writer. func Write(w io.Writer, blk Block) error { |
