mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 09:58:29 +02:00
Refactor: Move list print functions into print package (#273)
MV list issues -> print.IssuesList MV list labels -> print.LabelsList & task.LabelsExport MV list logins -> print.LoginsList MV list miles -> print.MilestonesList MV list pulls -> print.PullsList MV list releases -> print.ReleasesList MV list issues&pulls of mile -> print.IssuesPullsList MV list notification threads -> print.NotificationsList Unexport print.outputList Unexport print.outputMarkdown remove comd/flags dependency in print module Reviewed-on: https://gitea.com/gitea/tea/pulls/273 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-Authored-By: 6543 <6543@obermui.de> Co-Committed-By: 6543 <6543@obermui.de>
This commit is contained in:
@ -5,18 +5,15 @@
|
||||
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/tea/modules/task"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/muesli/termenv"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -46,54 +43,15 @@ var CmdLabels = cli.Command{
|
||||
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)
|
||||
if ctx.IsSet("save") {
|
||||
return task.LabelsExport(labels, ctx.String("save"))
|
||||
}
|
||||
|
||||
print.LabelsList(labels, flags.GlobalOutputValue)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user