github.com/coreos/mantle@v0.13.0/cmd/ore/gcloud/delete-images.go (about) 1 // Copyright 2017 CoreOS, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package gcloud 16 17 import ( 18 "fmt" 19 "os" 20 21 "github.com/spf13/cobra" 22 23 "github.com/coreos/mantle/platform/api/gcloud" 24 ) 25 26 var ( 27 cmdDeleteImage = &cobra.Command{ 28 Use: "delete-images <name>...", 29 Short: "Delete GCE images", 30 Run: runDeleteImage, 31 } 32 ) 33 34 func init() { 35 GCloud.AddCommand(cmdDeleteImage) 36 } 37 38 func runDeleteImage(cmd *cobra.Command, args []string) { 39 if len(args) == 0 { 40 fmt.Fprint(os.Stderr, "Specify image name(s).\n") 41 os.Exit(2) 42 } 43 44 exit := 0 45 pendings := map[string]*gcloud.Pending{} 46 for _, name := range args { 47 pending, err := api.DeleteImage(name) 48 if err != nil { 49 fmt.Fprintf(os.Stderr, "%v\n", err) 50 exit = 1 51 continue 52 } 53 pendings[name] = pending 54 } 55 for name, pending := range pendings { 56 if err := pending.Wait(); err != nil { 57 fmt.Fprintf(os.Stderr, "Deleting %q failed: %v\n", name, err) 58 exit = 1 59 } 60 } 61 os.Exit(exit) 62 }