RunE: func(cmd *cobra.Command, args []string) error {标签:文件,return,nil,err,outputWriter,追加,go,out From: https://www.cnblogs.com/cheyunhua/p/17122535.html
objects, err := apply.NewClusterFromArgs(args, genArgs)
if err != nil {
return err
}
data, err := yaml.MarshalYamlConfigs(objects...)
if err != nil {
return err
}
var outputWriter io.WriteCloser
switch out {
case "", "stdout":
outputWriter = os.Stdout
default:
outputWriter, err = os.Create(out)
}
if err != nil {
return err
}
defer outputWriter.Close()
_, err = fmt.Fprintln(outputWriter, string(data))
return err
},