label.go 907 字节
Newer Older
P
Pepper Lebeck-Jobe 已提交
1 2 3 4 5 6 7 8 9 10 11
package commands

import (
	"github.com/github/hub/github"
	"github.com/github/hub/ui"
	"github.com/github/hub/utils"
)


var (
	cmdLabel = &Command{
12
        Key: "label",
P
Pepper Lebeck-Jobe 已提交
13
		Run: listLabels,
14 15
		Usage: "issue label",
		Long: "List the labels available in this repository.",
P
Pepper Lebeck-Jobe 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
	}
)

func listLabels(cmd *Command, args *Args) {
	localRepo, err := github.LocalRepo()
	utils.Check(err)

	project, err := localRepo.MainProject()
	utils.Check(err)

	gh := github.NewClient(project.Host)

    if args.Noop {
		ui.Printf("Would request list of labels for %s\n", project)
	} else {
		labels, err := gh.FetchLabels(project)
		utils.Check(err)

		for _, label := range labels {
			ui.Printf(formatLabel(label))
		}
	}

	args.NoForward()
}

func formatLabel(label github.IssueLabel) string {
    format := "%l%n"

	placeholders := map[string]string{
		"l":  label.Name,
	}

	return ui.Expand(format, placeholders, false)
}