// deleteAllGCPPrinters finds all GCP printers associated with this
// connector, deletes them from GCP.
func deleteAllGCPPrinters() {
	config := getConfig()
	gcp := getGCP(config)

	printers, err := gcp.List()
	if err != nil {
		glog.Fatal(err)
	}

	ch := make(chan bool)
	for gcpID, name := range printers {
		go func(gcpID, name string) {
			err := gcp.Delete(gcpID)
			if err != nil {
				fmt.Printf("Failed to delete %s \"%s\": %s\n", gcpID, name, err)
			} else {
				fmt.Printf("Deleted %s \"%s\" from GCP\n", gcpID, name)
			}
			ch <- true
		}(gcpID, name)
	}

	for _ = range printers {
		<-ch
	}
}
// deleteAllGCPPrinters finds all GCP printers associated with this
// connector, deletes them from GCP.
func deleteAllGCPPrinters() {
	config, err := lib.ConfigFromFile()
	if err != nil {
		panic(err)
	}

	gcpXMPPPingIntervalDefault, err := time.ParseDuration(config.XMPPPingIntervalDefault)
	if err != nil {
		glog.Fatalf("Failed to parse xmpp ping interval default: %s", err)
	}

	gcp, err := gcp.NewGoogleCloudPrint(config.GCPBaseURL, config.RobotRefreshToken,
		config.UserRefreshToken, config.ProxyName, config.GCPOAuthClientID,
		config.GCPOAuthClientSecret, config.GCPOAuthAuthURL, config.GCPOAuthTokenURL,
		gcpXMPPPingIntervalDefault, 0, nil)
	if err != nil {
		glog.Fatal(err)
	}

	printers, err := gcp.List()
	if err != nil {
		glog.Fatal(err)
	}

	ch := make(chan bool)
	for gcpID, name := range printers {
		go func(gcpID, name string) {
			err := gcp.Delete(gcpID)
			if err != nil {
				fmt.Printf("Failed to delete %s \"%s\": %s\n", gcpID, name, err)
			} else {
				fmt.Printf("Deleted %s \"%s\" from GCP\n", gcpID, name)
			}
			ch <- true
		}(gcpID, name)
	}

	for _ = range printers {
		<-ch
	}
}
// deleteAllGCPPrinters finds all GCP printers associated with this
// connector, deletes them from GCP.
func deleteAllGCPPrinters(context *cli.Context) {
	config := getConfig(context)
	gcp := getGCP(config)

	printers, err := gcp.List()
	if err != nil {
		log.Fatalln(err)
	}

	var wg sync.WaitGroup
	for gcpID, name := range printers {
		wg.Add(1)
		go func(gcpID, name string) {
			err := gcp.Delete(gcpID)
			if err != nil {
				fmt.Printf("Failed to delete %s \"%s\": %s\n", gcpID, name, err)
			} else {
				fmt.Printf("Deleted %s \"%s\" from GCP\n", gcpID, name)
			}
			wg.Done()
		}(gcpID, name)
	}
	wg.Wait()
}