当前位置: 首页>>代码示例>>Golang>>正文


Golang api.NewClient函数代码示例

本文整理汇总了Golang中github.com/exercism/cli/api.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Tracks

// Tracks lists available tracks.
func Tracks(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	client := api.NewClient(c)

	tracks, err := client.Tracks()
	if err != nil {
		log.Fatal(err)
	}

	curr := user.NewCurriculum(tracks)
	fmt.Println("\nActive language tracks:")
	curr.Report(user.TrackActive)
	fmt.Println("\nInactive language tracks:")
	curr.Report(user.TrackInactive)

	msg := `
Related commands:
    exercism fetch (see 'exercism help fetch')
    exercism list (see 'exercism help list')
	`
	fmt.Println(msg)
}
开发者ID:Lin4ipsum,项目名称:cli,代码行数:26,代码来源:tracks.go

示例2: Status

// Status is a command that allows a user to view their progress in a given
// language track.
func Status(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	args := ctx.Args()

	if len(args) != 1 {
		fmt.Fprintf(os.Stderr, "Usage: exercism status TRACK_ID")
		os.Exit(1)
	}

	client := api.NewClient(c)
	trackID := args[0]
	status, err := client.Status(trackID)
	if err != nil {
		if err == api.ErrUnknownTrack {
			log.Fatalf("There is no track with ID '%s'.", trackID)
		} else {
			log.Fatal(err)
		}
	}

	fmt.Println(status)
}
开发者ID:petertseng,项目名称:cli,代码行数:27,代码来源:status.go

示例3: List

// List returns the full list of assignments for a given language
func List(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	args := ctx.Args()

	if len(args) != 1 {
		msg := "Usage: exercism list LANGUAGE"
		log.Fatal(msg)
	}

	language := args[0]
	client := api.NewClient(c)
	problems, err := client.List(language)
	if err != nil {
		if err == api.ErrUnknownLanguage {
			log.Fatalf("The requested language '%s' is unknown", language)
		}
		log.Fatal(err)
	}

	for _, p := range problems {
		fmt.Printf("%s\n", p)
	}
	fmt.Printf("\n%s\n\n", msgExplainFetch)
}
开发者ID:exercistas,项目名称:cli,代码行数:28,代码来源:list.go

示例4: Demo

// 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.")
}
开发者ID:exercistas,项目名称:cli,代码行数:28,代码来源:demo.go

示例5: List

// List returns the full list of assignments for a given track.
func List(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	args := ctx.Args()

	if len(args) != 1 {
		msg := "Usage: exercism list TRACK_ID"
		log.Fatal(msg)
	}

	trackID := args[0]
	client := api.NewClient(c)
	problems, err := client.List(trackID)
	if err != nil {
		if err == api.ErrUnknownTrack {
			log.Fatalf("There is no track with ID '%s'.", trackID)
		}
		log.Fatal(err)
	}

	for _, p := range problems {
		fmt.Printf("%s\n", p)
	}
	fmt.Printf("\n%s\n\n", msgExplainFetch)
}
开发者ID:Lin4ipsum,项目名称:cli,代码行数:28,代码来源:list.go

示例6: Fetch

// 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)
}
开发者ID:anxiousmodernman,项目名称:cli,代码行数:29,代码来源:fetch.go

示例7: Unsubmit

// Unsubmit deletes an iteration from the api.
// If no iteration is specified, the most recent iteration
// is deleted.
func Unsubmit(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}

	if !c.IsAuthenticated() {
		log.Fatal(msgPleaseAuthenticate)
	}

	client := api.NewClient(c)
	if err := client.Unsubmit(); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Your most recent submission was successfully deleted.")
}
开发者ID:exercistas,项目名称:cli,代码行数:20,代码来源:unsubmit.go

示例8: Open

// Open uses the given track and problem and opens it in the browser.
func Open(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	client := api.NewClient(c)

	args := ctx.Args()
	if len(args) != 2 {
		fmt.Fprintf(os.Stderr, "Usage: exercism open TRACK_ID PROBLEM")
		os.Exit(1)
	}

	trackID := args[0]
	slug := args[1]
	submission, err := client.SubmissionURL(trackID, slug)
	if err != nil {
		log.Fatal(err)
	}

	url := submission.URL
	// Escape characters are not allowed by cmd/bash.
	switch runtime.GOOS {
	case "windows":
		url = strings.Replace(url, "&", `^&`, -1)
	default:
		url = strings.Replace(url, "&", `\&`, -1)
	}

	// The command to open the browser is OS-dependent.
	var cmd *exec.Cmd
	switch runtime.GOOS {
	case "darwin":
		cmd = exec.Command("open", url)
	case "freebsd", "linux", "netbsd", "openbsd":
		cmd = exec.Command("xdg-open", url)
	case "windows":
		cmd = exec.Command("cmd", "/c", "start", url)
	}

	if err := cmd.Run(); err != nil {
		log.Fatal(err)
	}
}
开发者ID:petertseng,项目名称:cli,代码行数:45,代码来源:open.go

示例9: Fetch

// 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)
}
开发者ID:Lin4ipsum,项目名称:cli,代码行数:45,代码来源:fetch.go

示例10: Restore

// 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)
}
开发者ID:Lin4ipsum,项目名称:cli,代码行数:20,代码来源:restore.go

示例11: Status

// Status is a command that allows a user to view their progress in a given
// language track.
func Status(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	args := ctx.Args()

	if len(args) != 1 {
		log.Fatal("Usage: exercism status TRACK_ID")
	}

	client := api.NewClient(c)
	status, err := client.Status(args[0])
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(status)
}
开发者ID:Lin4ipsum,项目名称:cli,代码行数:21,代码来源:status.go

示例12: Unsubmit

// Unsubmit deletes the most recent submission from the API.
func Unsubmit(ctx *cli.Context) {
	if len(ctx.Args()) > 0 {
		log.Fatal("\nThe unsubmit command does not take any arguments, it deletes the most recent submission.\n\nTo delete a different submission, you'll need to do it from the website.")
	}

	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}

	if !c.IsAuthenticated() {
		log.Fatal(msgPleaseAuthenticate)
	}

	client := api.NewClient(c)
	if err := client.Unsubmit(); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Your most recent submission was successfully deleted.")
}
开发者ID:rwz,项目名称:cli,代码行数:22,代码来源:unsubmit.go

示例13: Download

// Download returns specified iteration with its related problem.
func Download(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	client := api.NewClient(c)

	args := ctx.Args()
	if len(args) != 1 {
		msg := "Usage: exercism download SUBMISSION_ID"
		log.Fatal(msg)
	}

	submission, err := client.Download(args[0])
	if err != nil {
		log.Fatal(err)
	}

	path := filepath.Join(c.Dir, "solutions", submission.Username, submission.TrackID, submission.Slug, args[0])

	if err := os.MkdirAll(path, 0755); err != nil {
		log.Fatal(err)
	}

	for name, contents := range submission.ProblemFiles {
		if err := ioutil.WriteFile(fmt.Sprintf("%s/%s", path, name), []byte(contents), 0755); err != nil {
			log.Fatalf("Unable to write file %s: %s", name, err)
		}
	}

	for name, contents := range submission.SolutionFiles {
		filename := strings.TrimPrefix(name, strings.ToLower("/"+submission.TrackID+"/"+submission.Slug+"/"))
		if err := ioutil.WriteFile(fmt.Sprintf("%s/%s", path, filename), []byte(contents), 0755); err != nil {
			log.Fatalf("Unable to write file %s: %s", name, err)
		}
	}

	fmt.Printf("Successfully downloaded submission.\n\nThe submission can be viewed at:\n %s\n\n", path)

}
开发者ID:Lin4ipsum,项目名称:cli,代码行数:41,代码来源:download.go

示例14: Skip

// Skip command allows a user to skip a specific problem
func Skip(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	args := ctx.Args()

	if len(args) != 2 {
		msg := "Usage: exercism skip LANGUAGE SLUG"
		log.Fatal(msg)
	}

	var (
		language = args[0]
		slug     = args[1]
	)

	client := api.NewClient(c)
	if err := client.Skip(language, slug); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Exercise %q in %q has been skipped.\n", slug, language)
}
开发者ID:exercistas,项目名称:cli,代码行数:25,代码来源:skip.go

示例15: Skip

// Skip allows a user to skip a specific problem.
func Skip(ctx *cli.Context) {
	c, err := config.New(ctx.GlobalString("config"))
	if err != nil {
		log.Fatal(err)
	}
	args := ctx.Args()

	if len(args) != 2 {
		msg := "Usage: exercism skip TRACK_ID PROBLEM"
		log.Fatal(msg)
	}

	var (
		trackID = args[0]
		slug    = args[1]
	)

	client := api.NewClient(c)
	if err := client.Skip(trackID, slug); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Exercise %q in %q has been skipped.\n", slug, trackID)
}
开发者ID:Lin4ipsum,项目名称:cli,代码行数:25,代码来源:skip.go


注:本文中的github.com/exercism/cli/api.NewClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。