Exemple #1
0
// Demo returns one problem for each active track.
func Demo(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}

	client := api.NewClient(c)

	problems, err := client.Demo()
	if err != nil {
		log.Fatal(err)
	}

	if dirOpt := ctx.String("dir"); dirOpt != "" {
		c.SetDir(dirOpt)
	}

	fmt.Printf("Your exercises will be saved at: %s\n", c.Dir)
	hw := user.NewHomework(problems, c)
	if err := hw.Save(); err != nil {
		log.Fatal(err)
	}

	hw.Report(user.HWAll)

	fmt.Println("Next step: choose a language, read the README, and make the test suite pass.")
}
Exemple #2
0
// Fetch downloads exercism problems and writes them to disk.
func Fetch(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	client := api.NewClient(c)

	problems, err := client.Fetch(ctx.Args())
	if err != nil {
		log.Fatal(err)
	}

	submissionInfo, err := client.Submissions()
	if err != nil {
		log.Fatal(err)
	}

	if err := setSubmissionState(problems, submissionInfo); err != nil {
		log.Fatal(err)
	}

	hw := user.NewHomework(problems, c)
	if err := hw.Save(); err != nil {
		log.Fatal(err)
	}

	hw.Summarize(user.HWAll)
}
Exemple #3
0
// Fetch downloads exercism problems and writes them to disk.
func Fetch(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	client := api.NewClient(c)

	problems, err := client.Fetch(ctx.Args())
	if err != nil {
		log.Fatal(err)
	}

	submissionInfo, err := client.Submissions()
	if err != nil {
		log.Fatal(err)
	}

	if err := setSubmissionState(problems, submissionInfo); err != nil {
		log.Fatal(err)
	}

	dirs, err := filepath.Glob(filepath.Join(c.Dir, "*"))
	if err != nil {
		log.Fatal(err)
	}

	dirMap := make(map[string]bool)
	for _, dir := range dirs {
		dirMap[dir] = true
	}
	hw := user.NewHomework(problems, c)

	if len(ctx.Args()) == 0 {
		if err := hw.RejectMissingTracks(dirMap); err != nil {
			log.Fatal(err)
		}
	}

	if err := hw.Save(); err != nil {
		log.Fatal(err)
	}

	hw.Summarize(user.HWAll)
}
Exemple #4
0
// Restore returns a user's solved problems.
func Restore(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}

	client := api.NewClient(c)

	problems, err := client.Restore()
	if err != nil {
		log.Fatal(err)
	}

	hw := user.NewHomework(problems, c)
	if err := hw.Save(); err != nil {
		log.Fatal(err)
	}
	hw.Summarize(user.HWNotSubmitted)
}