Skip to content

Commit a11b2ac

Browse files
authored
fix install change (#9)
1 parent 9664060 commit a11b2ac

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

cmd/protobuild/cmd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ func Main() *cli.Command {
482482
Name: "force",
483483
Usage: "force update protobuf plugin",
484484
Aliases: []string{"f"},
485-
Value: force,
485+
Value: false,
486486
Destination: &force,
487487
},
488488
},
@@ -501,8 +501,8 @@ func Main() *cli.Command {
501501
slog.Error("command not found", slog.Any("name", plgName))
502502
}
503503

504-
if err == nil && !force {
505-
slog.Info("command path", slog.Any("path", path))
504+
if err == nil && !globalCfg.changed && !force {
505+
slog.Info("no changes", slog.Any("path", path))
506506
continue
507507
}
508508

cmd/protobuild/yaml_types.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package protobuild
22

33
import (
4+
"github.com/pubgo/funk/assert"
45
"github.com/pubgo/funk/errors"
56
yaml "gopkg.in/yaml.v3"
67
)
@@ -32,3 +33,63 @@ func (p *pluginOpts) UnmarshalYAML(value *yaml.Node) error {
3233
return errors.Format("yaml kind type error, kind=%v data=%s", value.Kind, value.Value)
3334
}
3435
}
36+
37+
type YamlListType[T any] []T
38+
39+
func (p *YamlListType[T]) UnmarshalYAML(value *yaml.Node) error {
40+
if value.IsZero() {
41+
return nil
42+
}
43+
44+
switch value.Kind {
45+
case yaml.ScalarNode, yaml.MappingNode:
46+
var data T
47+
if err := value.Decode(&data); err != nil {
48+
return errors.WrapCaller(err)
49+
}
50+
*p = []T{data}
51+
return nil
52+
case yaml.SequenceNode:
53+
var data []T
54+
if err := value.Decode(&data); err != nil {
55+
return errors.WrapCaller(err)
56+
}
57+
*p = data
58+
return nil
59+
default:
60+
var val any
61+
assert.Exit(value.Decode(&val))
62+
return errors.Format("yaml kind type error, kind=%v data=%v", value.Kind, val)
63+
}
64+
}
65+
66+
type strOrObject map[string]any
67+
68+
func (p *strOrObject) UnmarshalYAML(value *yaml.Node) error {
69+
if value.IsZero() {
70+
return nil
71+
}
72+
73+
switch value.Kind {
74+
case yaml.ScalarNode:
75+
var data string
76+
if err := value.Decode(&data); err != nil {
77+
return errors.WrapCaller(err)
78+
}
79+
80+
*p = strOrObject(map[string]any{"name": &data})
81+
return nil
82+
case yaml.MappingNode:
83+
var data map[string]any
84+
if err := value.Decode(&data); err != nil {
85+
return errors.WrapCaller(err)
86+
}
87+
88+
*p = data
89+
return nil
90+
default:
91+
var val any
92+
assert.Exit(value.Decode(&val))
93+
return errors.Format("yaml kind type error,kind=%v data=%v", value.Kind, val)
94+
}
95+
}

0 commit comments

Comments
 (0)