1
0
mirror of https://gitea.com/gitea/tea.git synced 2024-06-30 06:45:26 +00:00
tea/cmd/labels/list.go
khmarbaise 846fb3072a Refactor tea labels command (#282)
Refactor tea labels command

Fix #278

Signed-off-by: Karl Heinz Marbaise <kama@soebes.de>

Refactor tea labels command
 - fixed formatting code.

Co-authored-by: Karl Heinz Marbaise <kama@soebes.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/282
Reviewed-by: 6543 <6543@obermui.de>
Reviewed-by: Norwin <noerw@noreply.gitea.io>
Co-Authored-By: khmarbaise <khmarbaise@noreply.gitea.io>
Co-Committed-By: khmarbaise <khmarbaise@noreply.gitea.io>
2020-12-09 03:06:15 +08:00

53 lines
1.3 KiB
Go

// Copyright 2020 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 labels
import (
"log"
"code.gitea.io/tea/cmd/flags"
"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/urfave/cli/v2"
)
// CmdLabelsList represents a sub command of labels to list labels
var CmdLabelsList = cli.Command{
Name: "ls",
Aliases: []string{"list"},
Usage: "List labels",
Description: "List labels",
Action: RunLabelsList,
Flags: append([]cli.Flag{
&cli.BoolFlag{
Name: "save",
Aliases: []string{"s"},
Usage: "Save all the labels as a file",
},
&flags.PaginationPageFlag,
&flags.PaginationLimitFlag,
}, flags.AllDefaultFlags...),
}
// RunLabelsList list labels.
func RunLabelsList(ctx *cli.Context) error {
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
labels, _, err := login.Client().ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ListOptions: flags.GetListOptions(ctx)})
if err != nil {
log.Fatal(err)
}
if ctx.IsSet("save") {
return task.LabelsExport(labels, ctx.String("save"))
}
print.LabelsList(labels, flags.GlobalOutputValue)
return nil
}