aboutsummaryrefslogtreecommitdiff
path: root/internal/scfg/scfg.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-04-06 09:26:46 +0800
committerRunxi Yu <me@runxiyu.org>2025-04-06 09:27:53 +0800
commitda1d8f4e7c332c7109427915e6459b10209cedce (patch)
tree280b921be3b51f93d82d916b4eaa89387b7102cc /internal/scfg/scfg.go
parentgit2c, git2d: Rename cmd1 and cmd2 descriptively (diff)
downloadforge-da1d8f4e7c332c7109427915e6459b10209cedce.tar.gz
forge-da1d8f4e7c332c7109427915e6459b10209cedce.tar.zst
forge-da1d8f4e7c332c7109427915e6459b10209cedce.zip
Move the Go stuff to ./forged/v0.1.32
Diffstat (limited to 'internal/scfg/scfg.go')
-rw-r--r--internal/scfg/scfg.go59
1 files changed, 0 insertions, 59 deletions
diff --git a/internal/scfg/scfg.go b/internal/scfg/scfg.go
deleted file mode 100644
index 4533e63..0000000
--- a/internal/scfg/scfg.go
+++ /dev/null
@@ -1,59 +0,0 @@
-// SPDX-License-Identifier: MIT
-// SPDX-FileCopyrightText: Copyright (c) 2020 Simon Ser <https://emersion.fr>
-
-// Package scfg parses and formats configuration files.
-// Note that this fork of scfg behaves differently from upstream scfg.
-package scfg
-
-import (
- "fmt"
-)
-
-// Block is a list of directives.
-type Block []*Directive
-
-// GetAll returns a list of directives with the provided name.
-func (blk Block) GetAll(name string) []*Directive {
- l := make([]*Directive, 0, len(blk))
- for _, child := range blk {
- if child.Name == name {
- l = append(l, child)
- }
- }
- return l
-}
-
-// Get returns the first directive with the provided name.
-func (blk Block) Get(name string) *Directive {
- for _, child := range blk {
- if child.Name == name {
- return child
- }
- }
- return nil
-}
-
-// Directive is a configuration directive.
-type Directive struct {
- Name string
- Params []string
-
- Children Block
-
- lineno int
-}
-
-// ParseParams extracts parameters from the directive. It errors out if the
-// user hasn't provided enough parameters.
-func (d *Directive) ParseParams(params ...*string) error {
- if len(d.Params) < len(params) {
- return fmt.Errorf("directive %q: want %v params, got %v", d.Name, len(params), len(d.Params))
- }
- for i, ptr := range params {
- if ptr == nil {
- continue
- }
- *ptr = d.Params[i]
- }
- return nil
-}