mirror of
https://gitea.com/gitea/tea
synced 2024-11-18 09:25:36 +00:00
f445ac7521
fix lint fix lint Move print TrackedTimesList to print package Move AbsPathWithExpansion to utils/path.go rename module intern to config Move Subcomands into it's own Packages Split times subcomands into own sourcefiles Split repos subcomands into own sourcefiles Split releases subcomands into own sourcefiles Split pulls subcomands into own sourcefiles Split milestones subcomands into own sourcefiles Split login subcomands into own sourcefiles Split labels subcomands into own sourcefiles split issues subcomands into own sourcefiles mv Move Interactive Login Creation to interact package Move Add Login function to intern/login.go apply from review lint: add description to exported func smal nits Move DetailViews stdout print func to print package Refactor: * Move Config & Login routines into intern package * rename global var in cmd * Move help func to utils Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/206 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
99 lines
2.1 KiB
Go
99 lines
2.1 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"strconv"
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
"code.gitea.io/tea/cmd/labels"
|
|
"code.gitea.io/tea/modules/config"
|
|
"code.gitea.io/tea/modules/print"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"github.com/muesli/termenv"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// CmdLabels represents to operate repositories' labels.
|
|
var CmdLabels = cli.Command{
|
|
Name: "labels",
|
|
Usage: "Manage issue labels",
|
|
Description: `Manage issue labels`,
|
|
Action: runLabels,
|
|
Subcommands: []*cli.Command{
|
|
&labels.CmdLabelCreate,
|
|
&labels.CmdLabelUpdate,
|
|
&labels.CmdLabelDelete,
|
|
},
|
|
Flags: append([]cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "save",
|
|
Aliases: []string{"s"},
|
|
Usage: "Save all the labels as a file",
|
|
},
|
|
&flags.PaginationPageFlag,
|
|
&flags.PaginationLimitFlag,
|
|
}, flags.AllDefaultFlags...),
|
|
}
|
|
|
|
func runLabels(ctx *cli.Context) error {
|
|
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
|
|
|
headers := []string{
|
|
"Index",
|
|
"Color",
|
|
"Name",
|
|
"Description",
|
|
}
|
|
|
|
var values [][]string
|
|
|
|
labels, _, err := login.Client().ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ListOptions: flags.GetListOptions(ctx)})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
if len(labels) == 0 {
|
|
print.OutputList(flags.GlobalOutputValue, headers, values)
|
|
return nil
|
|
}
|
|
|
|
p := termenv.ColorProfile()
|
|
|
|
fPath := ctx.String("save")
|
|
if len(fPath) > 0 {
|
|
f, err := os.Create(fPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
|
|
for _, label := range labels {
|
|
fmt.Fprintf(f, "#%s %s\n", label.Color, label.Name)
|
|
}
|
|
} else {
|
|
for _, label := range labels {
|
|
color := termenv.String(label.Color)
|
|
|
|
values = append(
|
|
values,
|
|
[]string{
|
|
strconv.FormatInt(label.ID, 10),
|
|
fmt.Sprint(color.Background(p.Color("#" + label.Color))),
|
|
label.Name,
|
|
label.Description,
|
|
},
|
|
)
|
|
}
|
|
print.OutputList(flags.GlobalOutputValue, headers, values)
|
|
}
|
|
|
|
return nil
|
|
}
|