From 2be69f92a4e83b21cecaf7f2144d9ba7debe2692 Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Mon, 21 Aug 2017 23:10:10 +0200 Subject: [PATCH] Add the label command This command can currently only list the labels associated with a git repository. In the future, it will also allow the creation of new labels and modifiaction of existing labels. --- commands/label.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 commands/label.go diff --git a/commands/label.go b/commands/label.go new file mode 100644 index 00000000..f1cf28b3 --- /dev/null +++ b/commands/label.go @@ -0,0 +1,60 @@ +package commands + +import ( + "github.com/github/hub/github" + "github.com/github/hub/ui" + "github.com/github/hub/utils" +) + + +var ( + cmdLabel = &Command{ + Run: listLabels, + Usage: ` +label +`, + Long: `Manage GitHub labels for the current repository. + +## Commands: + +With no arguments, show a list of open issues. +`, + } +) + +func init() { + CmdRunner.Use(cmdLabel) +} + +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) +} -- GitLab