mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 18:08:30 +02:00
replace flag globals, require context for commands (#291)
introduce TeaContext clean up InitCommand move GetListOptions to TeaContext ensure context for each command so we fail early with a good error message instead of "Error: 404" etc make linter happy Merge branch 'master' into refactor-global-flags move TeaContext & InitCommand to modules/context Merge branch 'master' into refactor-global-flags CI.restart() Merge branch 'master' into refactor-global-flags Merge branch 'master' into refactor-global-flags Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/291 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: Norwin <noerw@noreply.gitea.io> Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
@ -10,8 +10,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -43,13 +42,14 @@ var CmdLabelCreate = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func runLabelCreate(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runLabelCreate(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
labelFile := ctx.String("file")
|
||||
var err error
|
||||
if len(labelFile) == 0 {
|
||||
_, _, err = login.Client().CreateLabel(owner, repo, gitea.CreateLabelOption{
|
||||
_, _, err = ctx.Login.Client().CreateLabel(ctx.Owner, ctx.Repo, gitea.CreateLabelOption{
|
||||
Name: ctx.String("name"),
|
||||
Color: ctx.String("color"),
|
||||
Description: ctx.String("description"),
|
||||
@ -69,7 +69,7 @@ func runLabelCreate(ctx *cli.Context) error {
|
||||
if color == "" || name == "" {
|
||||
log.Printf("Line %d ignored because lack of enough fields: %s\n", i, line)
|
||||
} else {
|
||||
_, _, err = login.Client().CreateLabel(owner, repo, gitea.CreateLabelOption{
|
||||
_, _, err = ctx.Login.Client().CreateLabel(ctx.Owner, ctx.Repo, gitea.CreateLabelOption{
|
||||
Name: name,
|
||||
Color: color,
|
||||
Description: description,
|
||||
|
@ -7,8 +7,7 @@ package labels
|
||||
import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@ -27,10 +26,11 @@ var CmdLabelDelete = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func runLabelDelete(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runLabelDelete(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
_, err := login.Client().DeleteLabel(owner, repo, ctx.Int64("id"))
|
||||
_, err := ctx.Login.Client().DeleteLabel(ctx.Owner, ctx.Repo, ctx.Int64("id"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
|
||||
@ -35,10 +35,14 @@ var CmdLabelsList = cli.Command{
|
||||
}
|
||||
|
||||
// RunLabelsList list labels.
|
||||
func RunLabelsList(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func RunLabelsList(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
labels, _, err := login.Client().ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ListOptions: flags.GetListOptions(ctx)})
|
||||
client := ctx.Login.Client()
|
||||
labels, _, err := client.ListRepoLabels(ctx.Owner, ctx.Repo, gitea.ListLabelsOptions{
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -47,6 +51,6 @@ func RunLabelsList(ctx *cli.Context) error {
|
||||
return task.LabelsExport(labels, ctx.String("save"))
|
||||
}
|
||||
|
||||
print.LabelsList(labels, flags.GlobalOutputValue)
|
||||
print.LabelsList(labels, ctx.Output)
|
||||
return nil
|
||||
}
|
||||
|
@ -7,8 +7,7 @@ package labels
|
||||
import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -40,8 +39,9 @@ var CmdLabelUpdate = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func runLabelUpdate(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runLabelUpdate(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
id := ctx.Int64("id")
|
||||
var pName, pColor, pDescription *string
|
||||
@ -61,7 +61,7 @@ func runLabelUpdate(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
var err error
|
||||
_, _, err = login.Client().EditLabel(owner, repo, id, gitea.EditLabelOption{
|
||||
_, _, err = ctx.Login.Client().EditLabel(ctx.Owner, ctx.Repo, id, gitea.EditLabelOption{
|
||||
Name: pName,
|
||||
Color: pColor,
|
||||
Description: pDescription,
|
||||
|
Reference in New Issue
Block a user