summaryrefslogtreecommitdiff
path: root/plugin/special/stdin.go
diff options
context:
space:
mode:
authoranthropic-code-agent[bot] <[email protected]>2026-04-28 18:08:20 +0000
committerGitHub <[email protected]>2026-04-28 18:08:20 +0000
commitfbc2f20cdfc138b0146fcc61bcb7ed2c1776a076 (patch)
treefada69f06625575fbda4a0533dd95316d7d0d2b6 /plugin/special/stdin.go
parent6fbcfeba5b73e4ac50ab0257040103cadf524ea7 (diff)
Complete functional options pattern refactoring for special pluginclaude/refactor-plugins-functional-options
Agent-Logs-Url: https://github.com/Loyalsoldier/geoip/sessions/0483b641-15da-4630-a3ad-53f8d1c65fe9 Co-authored-by: Loyalsoldier <[email protected]>
Diffstat (limited to 'plugin/special/stdin.go')
-rw-r--r--plugin/special/stdin.go56
1 files changed, 41 insertions, 15 deletions
diff --git a/plugin/special/stdin.go b/plugin/special/stdin.go
index f2f9cf9c..8e4a2e28 100644
--- a/plugin/special/stdin.go
+++ b/plugin/special/stdin.go
@@ -17,14 +17,42 @@ const (
func init() {
lib.RegisterInputConfigCreator(TypeStdin, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
- return newStdin(action, data)
+ return NewStdinFromBytes(action, data)
})
- lib.RegisterInputConverter(TypeStdin, &Stdin{
+ lib.RegisterInputConverter(TypeStdin, &stdin{
Description: DescStdin,
})
}
-func newStdin(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
+func NewStdin(action lib.Action, opts ...lib.InputOption) lib.InputConverter {
+ s := &stdin{
+ Type: TypeStdin,
+ Action: action,
+ Description: DescStdin,
+ }
+
+ for _, opt := range opts {
+ if opt != nil {
+ opt(s)
+ }
+ }
+
+ return s
+}
+
+func WithStdinName(name string) lib.InputOption {
+ return func(s lib.InputConverter) {
+ s.(*stdin).Name = name
+ }
+}
+
+func WithStdinOnlyIPType(onlyIPType lib.IPType) lib.InputOption {
+ return func(s lib.InputConverter) {
+ s.(*stdin).OnlyIPType = onlyIPType
+ }
+}
+
+func NewStdinFromBytes(action lib.Action, data []byte) (lib.InputConverter, error) {
var tmp struct {
Name string `json:"name"`
OnlyIPType lib.IPType `json:"onlyIPType"`
@@ -40,16 +68,14 @@ func newStdin(action lib.Action, data json.RawMessage) (lib.InputConverter, erro
return nil, fmt.Errorf("❌ [type %s | action %s] missing name", TypeStdin, action)
}
- return &Stdin{
- Type: TypeStdin,
- Action: action,
- Description: DescStdin,
- Name: tmp.Name,
- OnlyIPType: tmp.OnlyIPType,
- }, nil
+ return NewStdin(
+ action,
+ WithStdinName(tmp.Name),
+ WithStdinOnlyIPType(tmp.OnlyIPType),
+ ), nil
}
-type Stdin struct {
+type stdin struct {
Type string
Action lib.Action
Description string
@@ -57,19 +83,19 @@ type Stdin struct {
OnlyIPType lib.IPType
}
-func (s *Stdin) GetType() string {
+func (s *stdin) GetType() string {
return s.Type
}
-func (s *Stdin) GetAction() lib.Action {
+func (s *stdin) GetAction() lib.Action {
return s.Action
}
-func (s *Stdin) GetDescription() string {
+func (s *stdin) GetDescription() string {
return s.Description
}
-func (s *Stdin) Input(container lib.Container) (lib.Container, error) {
+func (s *stdin) Input(container lib.Container) (lib.Container, error) {
entry := lib.NewEntry(s.Name)
scanner := bufio.NewScanner(os.Stdin)