77 "os"
88 "os/exec"
99 "path/filepath"
10+ "reflect"
1011
1112 "gopkg.in/yaml.v3"
1213)
@@ -51,12 +52,12 @@ func RunCmd(command string, arg ...string) error {
5152
5253func RunCmdWithOutput (command string , arg ... string ) ([]string , error ) {
5354 cmd := exec .Command (command , arg ... )
54-
55+
5556 output , err := cmd .Output ()
5657 if err != nil {
5758 return nil , fmt .Errorf ("error running command: %v" , err )
5859 }
59-
60+
6061 lines := bytes .Split (output , []byte ("\n " ))
6162 result := make ([]string , 0 , len (lines ))
6263 for _ , line := range lines {
@@ -65,7 +66,7 @@ func RunCmdWithOutput(command string, arg ...string) ([]string, error) {
6566 result = append (result , string (trimmed ))
6667 }
6768 }
68-
69+
6970 return result , nil
7071}
7172
@@ -127,6 +128,15 @@ func WriteYAML(url string, data any) error {
127128}
128129
129130func ReadYAML (path string , result any ) error {
131+ if result == nil {
132+ return fmt .Errorf ("result interface is nil" )
133+ }
134+
135+ rv := reflect .ValueOf (result )
136+ if rv .Kind () != reflect .Ptr || rv .IsNil () {
137+ return fmt .Errorf ("result must be a non-nil pointer" )
138+ }
139+
130140 file , err := os .Open (path )
131141 if err != nil {
132142 return err
0 commit comments