2019-10-19 12:54:16 +02:00
|
|
|
// 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 (
|
|
|
|
"log"
|
|
|
|
|
2020-09-30 07:11:33 +02:00
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
|
|
"code.gitea.io/tea/cmd/labels"
|
|
|
|
"code.gitea.io/tea/modules/config"
|
|
|
|
"code.gitea.io/tea/modules/print"
|
2020-12-08 11:28:54 +01:00
|
|
|
"code.gitea.io/tea/modules/task"
|
2019-10-19 12:54:16 +02:00
|
|
|
|
2020-09-30 07:11:33 +02:00
|
|
|
"code.gitea.io/sdk/gitea"
|
2020-01-04 18:44:25 +01:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-10-19 12:54:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// CmdLabels represents to operate repositories' labels.
|
|
|
|
var CmdLabels = cli.Command{
|
|
|
|
Name: "labels",
|
2020-10-02 17:46:51 +02:00
|
|
|
Aliases: []string{"label"},
|
2019-11-03 21:34:41 +01:00
|
|
|
Usage: "Manage issue labels",
|
|
|
|
Description: `Manage issue labels`,
|
2019-10-19 12:54:16 +02:00
|
|
|
Action: runLabels,
|
2020-01-04 18:44:25 +01:00
|
|
|
Subcommands: []*cli.Command{
|
2020-09-30 07:11:33 +02:00
|
|
|
&labels.CmdLabelCreate,
|
|
|
|
&labels.CmdLabelUpdate,
|
|
|
|
&labels.CmdLabelDelete,
|
2019-10-19 12:54:16 +02:00
|
|
|
},
|
2019-10-26 06:50:30 +02:00
|
|
|
Flags: append([]cli.Flag{
|
2020-01-04 18:44:25 +01:00
|
|
|
&cli.StringFlag{
|
2020-03-06 04:43:28 +01:00
|
|
|
Name: "save",
|
|
|
|
Aliases: []string{"s"},
|
|
|
|
Usage: "Save all the labels as a file",
|
2019-10-19 12:54:16 +02:00
|
|
|
},
|
2020-09-30 07:11:33 +02:00
|
|
|
&flags.PaginationPageFlag,
|
|
|
|
&flags.PaginationLimitFlag,
|
|
|
|
}, flags.AllDefaultFlags...),
|
2019-10-19 12:54:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func runLabels(ctx *cli.Context) error {
|
2020-09-30 07:11:33 +02:00
|
|
|
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
2019-10-19 12:54:16 +02:00
|
|
|
|
2020-09-30 07:11:33 +02:00
|
|
|
labels, _, err := login.Client().ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ListOptions: flags.GetListOptions(ctx)})
|
2019-10-19 12:54:16 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-12-08 11:28:54 +01:00
|
|
|
if ctx.IsSet("save") {
|
|
|
|
return task.LabelsExport(labels, ctx.String("save"))
|
2019-10-19 12:54:16 +02:00
|
|
|
}
|
|
|
|
|
2020-12-08 11:28:54 +01:00
|
|
|
print.LabelsList(labels, flags.GlobalOutputValue)
|
2019-10-19 12:54:16 +02:00
|
|
|
return nil
|
|
|
|
}
|