2020-12-08 19:06:15 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 01:40:02 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-08 19:06:15 +00:00
|
|
|
|
|
|
|
package labels
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
2020-12-15 17:38:22 +00:00
|
|
|
"code.gitea.io/tea/modules/context"
|
2020-12-08 19:06:15 +00:00
|
|
|
"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{
|
2020-12-16 16:47:40 +00:00
|
|
|
Name: "list",
|
|
|
|
Aliases: []string{"ls"},
|
2020-12-08 19:06:15 +00:00
|
|
|
Usage: "List labels",
|
|
|
|
Description: "List labels",
|
2022-09-13 18:14:02 +00:00
|
|
|
ArgsUsage: " ", // command does not accept arguments
|
2020-12-08 19:06:15 +00:00
|
|
|
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.
|
2020-12-15 17:38:22 +00:00
|
|
|
func RunLabelsList(cmd *cli.Context) error {
|
|
|
|
ctx := context.InitCommand(cmd)
|
|
|
|
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
|
|
|
|
|
|
|
client := ctx.Login.Client()
|
|
|
|
labels, _, err := client.ListRepoLabels(ctx.Owner, ctx.Repo, gitea.ListLabelsOptions{
|
|
|
|
ListOptions: ctx.GetListOptions(),
|
|
|
|
})
|
2020-12-08 19:06:15 +00:00
|
|
|
if err != nil {
|
2020-12-16 16:18:10 +00:00
|
|
|
return err
|
2020-12-08 19:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.IsSet("save") {
|
|
|
|
return task.LabelsExport(labels, ctx.String("save"))
|
|
|
|
}
|
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
print.LabelsList(labels, ctx.Output)
|
2020-12-08 19:06:15 +00:00
|
|
|
return nil
|
|
|
|
}
|