Ignore empty objects from streams and error when nothing passed to create

Passing zero objects to create should be an error
This commit is contained in:
Clayton Coleman
2015-01-14 13:06:53 -05:00
parent 31413c8727
commit ccdc20d90c
3 changed files with 15 additions and 5 deletions

View File

@@ -55,6 +55,7 @@ Examples:
Flatten().
Do()
count := 0
err = r.Visit(func(info *resource.Info) error {
data, err := info.Mapping.Codec.Encode(info.Object)
if err != nil {
@@ -66,11 +67,15 @@ Examples:
if err := resource.NewHelper(info.Client, info.Mapping).Create(info.Namespace, true, data); err != nil {
return err
}
count++
// TODO: if generation of names added to server side, change this to use the server's name
fmt.Fprintf(out, "%s\n", info.Name)
return nil
})
checkErr(err)
if count == 0 {
checkErr(fmt.Errorf("no objects passed to create"))
}
},
}
cmd.Flags().VarP(&flags.Filenames, "filename", "f", "Filename, directory, or URL to file to use to create the resource")