예제 #1
0
func (x *cmdEnableClassic) doEnable() (err error) {
	if classic.Enabled() {
		return fmt.Errorf(i18n.G("Classic dimension is already enabled."))
	}

	pbar := progress.NewTextProgress()
	if err := classic.Create(pbar); err != nil {
		return err
	}

	fmt.Println(i18n.G(`Classic dimension enabled on this snappy system.
Use “snappy shell classic” to enter the classic dimension.`))
	return nil
}
예제 #2
0
func wait(client *client.Client, id string) error {
	pb := progress.NewTextProgress()
	defer func() {
		pb.Finished()
		fmt.Print("\n")
	}()

	var lastID string
	for {
		chg, err := client.Change(id)
		if err != nil {
			return err
		}

		for _, t := range chg.Tasks {
			switch {
			case t.Status != "Doing":
				continue
			case t.Progress.Total == 1:
				pb.Spin(t.Summary)
			case t.ID == lastID:
				pb.Set(float64(t.Progress.Done))
			default:
				pb.Start(t.Summary, float64(t.Progress.Total))
				lastID = t.ID
			}
			break
		}

		if chg.Ready {
			if chg.Status == "Done" {
				return nil
			}

			if chg.Err != "" {
				return errors.New(chg.Err)
			}

			return fmt.Errorf("change finished in status %q with no error message", chg.Status)
		}

		// note this very purposely is not a ticker; we want
		// to sleep 100ms between calls, not call once every
		// 100ms.
		time.Sleep(100 * time.Millisecond)
	}
}