func (c *initCmd) initProgressTracker(d *lxd.Client, operation string) { handler := func(msg interface{}) { if msg == nil { return } event := msg.(map[string]interface{}) if event["type"].(string) != "operation" { return } if event["metadata"] == nil { return } md := event["metadata"].(map[string]interface{}) if !strings.HasSuffix(operation, md["id"].(string)) { return } if md["metadata"] == nil { return } if shared.StatusCode(md["status_code"].(float64)).IsFinal() { return } opMd := md["metadata"].(map[string]interface{}) _, ok := opMd["download_progress"] if ok { fmt.Printf(i18n.G("Retrieving image: %s")+"\r", opMd["download_progress"].(string)) } if opMd["download_progress"].(string) == "100%" { fmt.Printf("\n") } } go d.Monitor([]string{"operation"}, handler) }