migrate tea to urfave v3 (#760)

I tested this somewhat, but I haven't been using the cli before so I'm not sure if there are changes - there shouldn't be though.

Reviewed-on: https://gitea.com/gitea/tea/pulls/760
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: TheFox0x7 <thefox0x7@gmail.com>
Co-committed-by: TheFox0x7 <thefox0x7@gmail.com>
This commit is contained in:
TheFox0x7
2025-06-10 05:19:59 +00:00
committed by Lunny Xiao
parent 5420af1dfa
commit 0e54bae0c4
91 changed files with 686 additions and 608 deletions

View File

@ -4,10 +4,12 @@
package cmd
import (
stdctx "context"
"code.gitea.io/tea/cmd/admin/users"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdAdmin represents the namespace of admin commands.
@ -17,10 +19,10 @@ var CmdAdmin = cli.Command{
Usage: "Operations requiring admin access on the Gitea instance",
Aliases: []string{"a"},
Category: catMisc,
Action: func(cmd *cli.Context) error {
Action: func(_ stdctx.Context, cmd *cli.Command) error {
return cli.ShowSubcommandHelp(cmd)
},
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&cmdAdminUsers,
},
}
@ -29,19 +31,19 @@ var cmdAdminUsers = cli.Command{
Name: "users",
Aliases: []string{"u"},
Usage: "Manage registered users",
Action: func(ctx *cli.Context) error {
if ctx.Args().Len() == 1 {
return runAdminUserDetail(ctx, ctx.Args().First())
Action: func(ctx stdctx.Context, cmd *cli.Command) error {
if cmd.Args().Len() == 1 {
return runAdminUserDetail(ctx, cmd, cmd.Args().First())
}
return users.RunUserList(ctx)
return users.RunUserList(ctx, cmd)
},
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&users.CmdUserList,
},
Flags: users.CmdUserList.Flags,
}
func runAdminUserDetail(cmd *cli.Context, u string) error {
func runAdminUserDetail(_ stdctx.Context, cmd *cli.Command, u string) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()
user, _, err := client.GetUserInfo(u)

View File

@ -4,12 +4,14 @@
package users
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
var userFieldsFlag = flags.FieldsFlag(print.UserFields, []string{
@ -31,7 +33,7 @@ var CmdUserList = cli.Command{
}
// RunUserList list users
func RunUserList(cmd *cli.Context) error {
func RunUserList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
fields, err := userFieldsFlag.GetValues(cmd)

View File

@ -7,7 +7,7 @@ import (
"code.gitea.io/tea/cmd/attachments"
"code.gitea.io/tea/cmd/flags"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdReleaseAttachments represents a release attachment (file attachment)
@ -19,7 +19,7 @@ var CmdReleaseAttachments = cli.Command{
Description: "Manage release assets",
ArgsUsage: " ", // command does not accept arguments
Action: attachments.RunReleaseAttachmentList,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&attachments.CmdReleaseAttachmentList,
&attachments.CmdReleaseAttachmentCreate,
&attachments.CmdReleaseAttachmentDelete,

View File

@ -4,6 +4,7 @@
package attachments
import (
stdctx "context"
"fmt"
"os"
"path/filepath"
@ -11,7 +12,7 @@ import (
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdReleaseAttachmentCreate represents a sub command of Release Attachments to create a release attachment
@ -25,7 +26,7 @@ var CmdReleaseAttachmentCreate = cli.Command{
Flags: flags.AllDefaultFlags,
}
func runReleaseAttachmentCreate(cmd *cli.Context) error {
func runReleaseAttachmentCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -4,13 +4,14 @@
package attachments
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdReleaseAttachmentDelete represents a sub command of Release Attachments to delete a release attachment
@ -30,7 +31,7 @@ var CmdReleaseAttachmentDelete = cli.Command{
}, flags.AllDefaultFlags...),
}
func runReleaseAttachmentDelete(cmd *cli.Context) error {
func runReleaseAttachmentDelete(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -4,6 +4,7 @@
package attachments
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
@ -11,7 +12,7 @@ import (
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdReleaseAttachmentList represents a sub command of release attachment to list release attachments
@ -29,7 +30,7 @@ var CmdReleaseAttachmentList = cli.Command{
}
// RunReleaseAttachmentList list release attachments
func RunReleaseAttachmentList(cmd *cli.Context) error {
func RunReleaseAttachmentList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -4,6 +4,7 @@
package cmd
import (
"context"
"fmt"
"io"
"net/http"
@ -11,7 +12,7 @@ import (
"os/exec"
"github.com/adrg/xdg"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdAutocomplete manages autocompletion
@ -31,9 +32,9 @@ var CmdAutocomplete = cli.Command{
Action: runAutocompleteAdd,
}
func runAutocompleteAdd(ctx *cli.Context) error {
func runAutocompleteAdd(_ context.Context, cmd *cli.Command) error {
var remoteFile, localFile, cmds string
shell := ctx.Args().First()
shell := cmd.Args().First()
switch shell {
case "zsh":
@ -55,10 +56,10 @@ func runAutocompleteAdd(ctx *cli.Context) error {
// fish is different, in that urfave/cli provides a generator for the shell script needed.
// this also means that the fish completion can become out of sync with the tea binary!
// writing to this directory suffices, as fish reads files there on startup, no cmds needed.
return writeFishAutoCompleteFile(ctx)
return writeFishAutoCompleteFile(cmd)
default:
return fmt.Errorf("Must specify valid %s", ctx.Command.ArgsUsage)
return fmt.Errorf("Must specify valid %s", cmd.ArgsUsage)
}
localPath, err := xdg.ConfigFile("tea/" + localFile)
@ -71,7 +72,7 @@ func runAutocompleteAdd(ctx *cli.Context) error {
return err
}
if ctx.Bool("install") {
if cmd.Bool("install") {
fmt.Println("Installing in your shellrc")
installer := exec.Command(shell, "-c", cmds)
if shell == "powershell" {
@ -109,14 +110,14 @@ func writeRemoteAutoCompleteFile(file, destPath string) error {
return err
}
func writeFishAutoCompleteFile(ctx *cli.Context) error {
func writeFishAutoCompleteFile(cmd *cli.Command) error {
// NOTE: to make sure this file is in sync with tea commands, we'd need to
// - check if the file exists
// - if it does, check if the tea version that wrote it is the currently running version
// - if not, rewrite the file
// on each application run
// NOTE: this generates a completion that also suggests file names, which looks kinda messy..
script, err := ctx.App.ToFishCompletion()
script, err := cmd.ToFishCompletion()
if err != nil {
return err
}

View File

@ -4,9 +4,11 @@
package cmd
import (
"context"
"code.gitea.io/tea/cmd/branches"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdBranches represents to login a gitea server.
@ -18,7 +20,7 @@ var CmdBranches = cli.Command{
Description: `Lists branches when called without argument. If a branch is provided, will show it in detail.`,
ArgsUsage: "[<branch name>]",
Action: runBranches,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&branches.CmdBranchesList,
&branches.CmdBranchesProtect,
&branches.CmdBranchesUnprotect,
@ -31,6 +33,6 @@ var CmdBranches = cli.Command{
}, branches.CmdBranchesList.Flags...),
}
func runBranches(ctx *cli.Context) error {
return branches.RunBranchesList(ctx)
func runBranches(ctx context.Context, cmd *cli.Command) error {
return branches.RunBranchesList(ctx, cmd)
}

View File

@ -4,12 +4,14 @@
package branches
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
var branchFieldsFlag = flags.FieldsFlag(print.BranchFields, []string{
@ -35,7 +37,7 @@ var CmdBranchesList = cli.Command{
}
// RunBranchesList list branches
func RunBranchesList(cmd *cli.Context) error {
func RunBranchesList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,13 +4,14 @@
package branches
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdBranchesProtectFlags Flags for command protect/unprotect
@ -43,7 +44,7 @@ var CmdBranchesUnprotect = cli.Command{
}
// RunBranchesProtect function to protect/unprotect a list of branches
func RunBranchesProtect(cmd *cli.Context) error {
func RunBranchesProtect(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,6 +4,7 @@
package cmd
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
@ -14,7 +15,7 @@ import (
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdRepoClone represents a sub command of repos to create a local copy
@ -45,18 +46,18 @@ When a host is specified in the repo-slug, it will override the login specified
},
}
func runRepoClone(cmd *cli.Context) error {
ctx := context.InitCommand(cmd)
func runRepoClone(ctx stdctx.Context, cmd *cli.Command) error {
teaCmd := context.InitCommand(cmd)
args := ctx.Args()
args := teaCmd.Args()
if args.Len() < 1 {
return cli.ShowCommandHelp(cmd, "clone")
return cli.ShowCommandHelp(ctx, cmd, "clone")
}
dir := args.Get(1)
var (
login *config.Login = ctx.Login
owner string = ctx.Login.User
login *config.Login = teaCmd.Login
owner string = teaCmd.Login.User
repo string
)
@ -81,7 +82,7 @@ func runRepoClone(cmd *cli.Context) error {
owner,
repo,
interact.PromptPassword,
ctx.Int("depth"),
teaCmd.Int("depth"),
)
return err

133
cmd/cmd.go Normal file
View File

@ -0,0 +1,133 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
// Tea is command line tool for Gitea.
package cmd // import "code.gitea.io/tea"
import (
"fmt"
"runtime"
"strings"
"github.com/urfave/cli/v3"
)
// Version holds the current tea version
var Version = "development"
// Tags holds the build tags used
var Tags = ""
// SDK holds the sdk version from go.mod
var SDK = ""
// App creates and returns a tea Command with all subcommands set
// it was separated from main so docs can be generated for it
func App() *cli.Command {
// make parsing tea --version easier, by printing /just/ the version string
cli.VersionPrinter = func(c *cli.Command) { fmt.Fprintln(c.Writer, c.Version) }
return &cli.Command{
Name: "tea",
Usage: "command line tool to interact with Gitea",
Description: appDescription,
CustomHelpTemplate: helpTemplate,
Version: formatVersion(),
Commands: []*cli.Command{
&CmdLogin,
&CmdLogout,
&CmdAutocomplete,
&CmdWhoami,
&CmdIssues,
&CmdPulls,
&CmdLabels,
&CmdMilestones,
&CmdReleases,
&CmdTrackedTimes,
&CmdOrgs,
&CmdRepos,
&CmdBranches,
&CmdAddComment,
&CmdOpen,
&CmdNotifications,
&CmdRepoClone,
&CmdAdmin,
},
EnableShellCompletion: true,
}
}
func formatVersion() string {
version := fmt.Sprintf("Version: %s\tgolang: %s",
bold(Version),
strings.ReplaceAll(runtime.Version(), "go", ""))
if len(Tags) != 0 {
version += fmt.Sprintf("\tbuilt with: %s", strings.Replace(Tags, " ", ", ", -1))
}
if len(SDK) != 0 {
version += fmt.Sprintf("\tgo-sdk: %s", SDK)
}
return version
}
var appDescription = `tea is a productivity helper for Gitea. It can be used to manage most entities on
one or multiple Gitea instances & provides local helpers like 'tea pr checkout'.
tea tries to make use of context provided by the repository in $PWD if available.
tea works best in a upstream/fork workflow, when the local main branch tracks the
upstream repo. tea assumes that local git state is published on the remote before
doing operations with tea. Configuration is persisted in $XDG_CONFIG_HOME/tea.
`
var helpTemplate = bold(`
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}`) + `
{{if .Version}}{{if not .HideVersion}}version {{.Version}}{{end}}{{end}}
USAGE
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .Commands}} command [subcommand] [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}}
DESCRIPTION
{{.Description | nindent 3 | trim}}{{end}}{{if .VisibleCommands}}
COMMANDS{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
OPTIONS
{{range $index, $option := .VisibleFlags}}{{if $index}}
{{end}}{{$option}}{{end}}{{end}}
EXAMPLES
tea login add # add a login once to get started
tea pulls # list open pulls for the repo in $PWD
tea pulls --repo $HOME/foo # list open pulls for the repo in $HOME/foo
tea pulls --remote upstream # list open pulls for the repo pointed at by
# your local "upstream" git remote
# list open pulls for any gitea repo at the given login instance
tea pulls --repo gitea/tea --login gitea.com
tea milestone issues 0.7.0 # view open issues for milestone '0.7.0'
tea issue 189 # view contents of issue 189
tea open 189 # open web ui for issue 189
tea open milestones # open web ui for milestones
# send gitea desktop notifications every 5 minutes (bash + libnotify)
while :; do tea notifications --mine -o simple | xargs -i notify-send {}; sleep 300; done
ABOUT
Written & maintained by The Gitea Authors.
If you find a bug or want to contribute, we'll welcome you at https://gitea.com/gitea/tea.
More info about Gitea itself on https://about.gitea.com.
`
func bold(t string) string {
return fmt.Sprintf("\033[1m%s\033[0m", t)
}

View File

@ -4,6 +4,7 @@
package cmd
import (
stdctx "context"
"fmt"
"io"
"strings"
@ -17,7 +18,7 @@ import (
"code.gitea.io/sdk/gitea"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdAddComment is the main command to operate with notifications
@ -32,7 +33,7 @@ var CmdAddComment = cli.Command{
Flags: flags.AllDefaultFlags,
}
func runAddComment(cmd *cli.Context) error {
func runAddComment(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
@ -49,7 +50,7 @@ func runAddComment(cmd *cli.Context) error {
body := strings.Join(ctx.Args().Tail(), " ")
if interact.IsStdinPiped() {
// custom solution until https://github.com/AlecAivazis/survey/issues/328 is fixed
if bodyStdin, err := io.ReadAll(ctx.App.Reader); err != nil {
if bodyStdin, err := io.ReadAll(ctx.Reader); err != nil {
return err
} else if len(bodyStdin) != 0 {
body = strings.Join([]string{body, string(bodyStdin)}, "\n\n")

View File

@ -1,55 +0,0 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/urfave/cli/v2"
)
// CmdDocs generates markdown for tea
var CmdDocs = cli.Command{
Name: "docs",
Hidden: true,
Description: "Generate CLI docs",
Action: runDocs,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "out",
Usage: "Path to output docs to, otherwise prints to stdout",
Aliases: []string{"o"},
},
},
}
func runDocs(ctx *cli.Context) error {
md, err := ctx.App.ToMarkdown()
if err != nil {
return err
}
outPath := ctx.String("out")
if outPath == "" {
fmt.Print(md)
return nil
}
if err := os.MkdirAll(filepath.Dir(outPath), os.ModePerm); err != nil {
return err
}
fi, err := os.Create(outPath)
if err != nil {
return err
}
defer fi.Close()
if _, err := fi.WriteString(md); err != nil {
return err
}
return nil
}

View File

@ -8,7 +8,7 @@ import (
"strings"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CsvFlag is a wrapper around cli.StringFlag, with an added GetValues() method
@ -38,8 +38,8 @@ func NewCsvFlag(name, usage string, aliases, availableValues, defaults []string)
}
// GetValues returns the value of the flag, parsed as a commaseparated list
func (f CsvFlag) GetValues(ctx *cli.Context) ([]string, error) {
val := ctx.String(f.Name)
func (f CsvFlag) GetValues(cmd *cli.Command) ([]string, error) {
val := cmd.String(f.Name)
selection := strings.Split(val, ",")
if f.AvailableFields != nil && val != "" {
for _, field := range selection {

View File

@ -4,7 +4,7 @@
package flags
import (
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// LoginFlag provides flag to specify tea login profile

View File

@ -13,7 +13,7 @@ import (
"code.gitea.io/tea/modules/task"
"github.com/araddon/dateparse"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// StateFlag provides flag to specify issue/pr state, defaulting to "open"

View File

@ -4,6 +4,7 @@
package cmd
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/issues"
@ -12,7 +13,7 @@ import (
"code.gitea.io/tea/modules/print"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdIssues represents to login a gitea server.
@ -24,7 +25,7 @@ var CmdIssues = cli.Command{
Description: `Lists issues when called without argument. If issue index is provided, will show it in detail.`,
ArgsUsage: "[<issue index>]",
Action: runIssues,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&issues.CmdIssuesList,
&issues.CmdIssuesCreate,
&issues.CmdIssuesEdit,
@ -39,14 +40,14 @@ var CmdIssues = cli.Command{
}, issues.CmdIssuesList.Flags...),
}
func runIssues(ctx *cli.Context) error {
if ctx.Args().Len() == 1 {
return runIssueDetail(ctx, ctx.Args().First())
func runIssues(ctx stdctx.Context, cmd *cli.Command) error {
if cmd.Args().Len() == 1 {
return runIssueDetail(ctx, cmd, cmd.Args().First())
}
return issues.RunIssuesList(ctx)
return issues.RunIssuesList(ctx, cmd)
}
func runIssueDetail(cmd *cli.Context, index string) error {
func runIssueDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,6 +4,7 @@
package issues
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
@ -12,7 +13,7 @@ import (
"code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdIssuesClose represents a sub command of issues to close an issue
@ -21,15 +22,15 @@ var CmdIssuesClose = cli.Command{
Usage: "Change state of one ore more issues to 'closed'",
Description: `Change state of one ore more issues to 'closed'`,
ArgsUsage: "<issue index> [<issue index>...]",
Action: func(ctx *cli.Context) error {
Action: func(ctx stdctx.Context, cmd *cli.Command) error {
var s = gitea.StateClosed
return editIssueState(ctx, gitea.EditIssueOption{State: &s})
return editIssueState(ctx, cmd, gitea.EditIssueOption{State: &s})
},
Flags: flags.AllDefaultFlags,
}
// editIssueState abstracts the arg parsing to edit the given issue
func editIssueState(cmd *cli.Context, opts gitea.EditIssueOption) error {
func editIssueState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditIssueOption) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.Args().Len() == 0 {

View File

@ -4,12 +4,14 @@
package issues
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdIssuesCreate represents a sub command of issues to create issue
@ -23,7 +25,7 @@ var CmdIssuesCreate = cli.Command{
Flags: flags.IssuePRCreateFlags,
}
func runIssuesCreate(cmd *cli.Context) error {
func runIssuesCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -6,14 +6,15 @@ package issues
import (
"fmt"
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/print"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdIssuesEdit is the subcommand of issues to edit issues
@ -28,7 +29,7 @@ use an empty string (eg. --milestone "").`,
Flags: flags.IssuePREditFlags,
}
func runIssuesEdit(cmd *cli.Context) error {
func runIssuesEdit(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,6 +4,7 @@
package issues
import (
stdctx "context"
"fmt"
"time"
@ -13,7 +14,7 @@ import (
"code.gitea.io/sdk/gitea"
"github.com/araddon/dateparse"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
var issueFieldsFlag = flags.FieldsFlag(print.IssueFields, []string{
@ -32,7 +33,7 @@ var CmdIssuesList = cli.Command{
}
// RunIssuesList list issues
func RunIssuesList(cmd *cli.Context) error {
func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
state := gitea.StateOpen

View File

@ -4,10 +4,12 @@
package issues
import (
"context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdIssuesReopen represents a sub command of issues to open an issue
@ -17,9 +19,9 @@ var CmdIssuesReopen = cli.Command{
Usage: "Change state of one or more issues to 'open'",
Description: `Change state of one or more issues to 'open'`,
ArgsUsage: "<issue index> [<issue index>...]",
Action: func(ctx *cli.Context) error {
Action: func(ctx context.Context, cmd *cli.Command) error {
var s = gitea.StateOpen
return editIssueState(ctx, gitea.EditIssueOption{State: &s})
return editIssueState(ctx, cmd, gitea.EditIssueOption{State: &s})
},
Flags: flags.AllDefaultFlags,
}

View File

@ -4,10 +4,11 @@
package cmd
import (
"context"
"fmt"
"code.gitea.io/tea/cmd/labels"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLabels represents to operate repositories' labels.
@ -19,7 +20,7 @@ var CmdLabels = cli.Command{
Description: `Manage issue labels`,
ArgsUsage: " ", // command does not accept arguments
Action: runLabels,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&labels.CmdLabelsList,
&labels.CmdLabelCreate,
&labels.CmdLabelUpdate,
@ -28,13 +29,13 @@ var CmdLabels = cli.Command{
Flags: labels.CmdLabelsList.Flags,
}
func runLabels(ctx *cli.Context) error {
if ctx.Args().Len() == 1 {
return runLabelsDetails(ctx)
func runLabels(ctx context.Context, cmd *cli.Command) error {
if cmd.Args().Len() == 1 {
return runLabelsDetails(cmd)
}
return labels.RunLabelsList(ctx)
return labels.RunLabelsList(ctx, cmd)
}
func runLabelsDetails(ctx *cli.Context) error {
func runLabelsDetails(cmd *cli.Command) error {
return fmt.Errorf("Not yet implemented")
}

View File

@ -5,6 +5,7 @@ package labels
import (
"bufio"
stdctx "context"
"log"
"os"
"strings"
@ -13,7 +14,7 @@ import (
"code.gitea.io/tea/modules/context"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLabelCreate represents a sub command of labels to create label.
@ -44,7 +45,7 @@ var CmdLabelCreate = cli.Command{
}, flags.AllDefaultFlags...),
}
func runLabelCreate(cmd *cli.Context) error {
func runLabelCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,10 +4,12 @@
package labels
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLabelDelete represents a sub command of labels to delete label.
@ -26,7 +28,7 @@ var CmdLabelDelete = cli.Command{
}, flags.AllDefaultFlags...),
}
func runLabelDelete(cmd *cli.Context) error {
func runLabelDelete(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,13 +4,15 @@
package labels
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/tea/modules/task"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLabelsList represents a sub command of labels to list labels
@ -33,7 +35,7 @@ var CmdLabelsList = cli.Command{
}
// RunLabelsList list labels.
func RunLabelsList(cmd *cli.Context) error {
func RunLabelsList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,11 +4,13 @@
package labels
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLabelUpdate represents a sub command of labels to update label.
@ -38,7 +40,7 @@ var CmdLabelUpdate = cli.Command{
}, flags.AllDefaultFlags...),
}
func runLabelUpdate(cmd *cli.Context) error {
func runLabelUpdate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,13 +4,14 @@
package cmd
import (
"context"
"fmt"
"code.gitea.io/tea/cmd/login"
"code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/print"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLogin represents to login a gitea server.
@ -22,7 +23,7 @@ var CmdLogin = cli.Command{
Description: `Log in to a Gitea server`,
ArgsUsage: "[<login name>]",
Action: runLogins,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&login.CmdLoginList,
&login.CmdLoginAdd,
&login.CmdLoginEdit,
@ -33,11 +34,11 @@ var CmdLogin = cli.Command{
},
}
func runLogins(ctx *cli.Context) error {
if ctx.Args().Len() == 1 {
return runLoginDetail(ctx.Args().First())
func runLogins(ctx context.Context, cmd *cli.Command) error {
if cmd.Args().Len() == 1 {
return runLoginDetail(cmd.Args().First())
}
return login.RunLoginList(ctx)
return login.RunLoginList(ctx, cmd)
}
func runLoginDetail(name string) error {

View File

@ -4,11 +4,13 @@
package login
import (
"context"
"code.gitea.io/tea/modules/auth"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLoginAdd represents to login a gitea server.
@ -27,7 +29,7 @@ var CmdLoginAdd = cli.Command{
Name: "url",
Aliases: []string{"u"},
Value: "https://gitea.com",
EnvVars: []string{"GITEA_SERVER_URL"},
Sources: cli.EnvVars("GITEA_SERVER_URL"),
Usage: "Server URL",
},
&cli.BoolFlag{
@ -39,30 +41,30 @@ var CmdLoginAdd = cli.Command{
Name: "token",
Aliases: []string{"t"},
Value: "",
EnvVars: []string{"GITEA_SERVER_TOKEN"},
Sources: cli.EnvVars("GITEA_SERVER_TOKEN"),
Usage: "Access token. Can be obtained from Settings > Applications",
},
&cli.StringFlag{
Name: "user",
Value: "",
EnvVars: []string{"GITEA_SERVER_USER"},
Sources: cli.EnvVars("GITEA_SERVER_USER"),
Usage: "User for basic auth (will create token)",
},
&cli.StringFlag{
Name: "password",
Aliases: []string{"pwd"},
Value: "",
EnvVars: []string{"GITEA_SERVER_PASSWORD"},
Sources: cli.EnvVars("GITEA_SERVER_PASSWORD"),
Usage: "Password for basic auth (will create token)",
},
&cli.StringFlag{
Name: "otp",
EnvVars: []string{"GITEA_SERVER_OTP"},
Sources: cli.EnvVars("GITEA_SERVER_OTP"),
Usage: "OTP token for auth, if necessary",
},
&cli.StringFlag{
Name: "scopes",
EnvVars: []string{"GITEA_SCOPES"},
Sources: cli.EnvVars("GITEA_SCOPES"),
Usage: "Token scopes to add when creating a new token, separated by a comma",
},
&cli.StringFlag{
@ -107,53 +109,53 @@ var CmdLoginAdd = cli.Command{
Action: runLoginAdd,
}
func runLoginAdd(ctx *cli.Context) error {
func runLoginAdd(_ context.Context, cmd *cli.Command) error {
// if no args create login interactive
if ctx.NumFlags() == 0 {
if cmd.NumFlags() == 0 {
return interact.CreateLogin()
}
// if OAuth flag is provided, use OAuth2 PKCE flow
if ctx.Bool("oauth") {
if cmd.Bool("oauth") {
opts := auth.OAuthOptions{
Name: ctx.String("name"),
URL: ctx.String("url"),
Insecure: ctx.Bool("insecure"),
Name: cmd.String("name"),
URL: cmd.String("url"),
Insecure: cmd.Bool("insecure"),
}
// Only set clientID if provided
if ctx.String("client-id") != "" {
opts.ClientID = ctx.String("client-id")
if cmd.String("client-id") != "" {
opts.ClientID = cmd.String("client-id")
}
// Only set redirect URL if provided
if ctx.String("redirect-url") != "" {
opts.RedirectURL = ctx.String("redirect-url")
if cmd.String("redirect-url") != "" {
opts.RedirectURL = cmd.String("redirect-url")
}
return auth.OAuthLoginWithFullOptions(opts)
}
sshAgent := false
if ctx.String("ssh-agent-key") != "" || ctx.String("ssh-agent-principal") != "" {
if cmd.String("ssh-agent-key") != "" || cmd.String("ssh-agent-principal") != "" {
sshAgent = true
}
// else use args to add login
return task.CreateLogin(
ctx.String("name"),
ctx.String("token"),
ctx.String("user"),
ctx.String("password"),
ctx.String("otp"),
ctx.String("scopes"),
ctx.String("ssh-key"),
ctx.String("url"),
ctx.String("ssh-agent-principal"),
ctx.String("ssh-agent-key"),
ctx.Bool("insecure"),
cmd.String("name"),
cmd.String("token"),
cmd.String("user"),
cmd.String("password"),
cmd.String("otp"),
cmd.String("scopes"),
cmd.String("ssh-key"),
cmd.String("url"),
cmd.String("ssh-agent-principal"),
cmd.String("ssh-agent-key"),
cmd.Bool("insecure"),
sshAgent,
!ctx.Bool("no-version-check"),
ctx.Bool("helper"),
!cmd.Bool("no-version-check"),
cmd.Bool("helper"),
)
}

View File

@ -4,12 +4,13 @@
package login
import (
"context"
"fmt"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/config"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLoginSetDefault represents to login a gitea server.
@ -22,8 +23,8 @@ var CmdLoginSetDefault = cli.Command{
Flags: []cli.Flag{&flags.OutputFlag},
}
func runLoginSetDefault(ctx *cli.Context) error {
if ctx.Args().Len() == 0 {
func runLoginSetDefault(_ context.Context, cmd *cli.Command) error {
if cmd.Args().Len() == 0 {
l, err := config.GetDefaultLogin()
if err != nil {
return err
@ -32,6 +33,6 @@ func runLoginSetDefault(ctx *cli.Context) error {
return nil
}
name := ctx.Args().First()
name := cmd.Args().First()
return config.SetDefaultLogin(name)
}

View File

@ -4,12 +4,13 @@
package login
import (
"context"
"errors"
"log"
"code.gitea.io/tea/modules/config"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLoginDelete is a command to delete a login
@ -23,7 +24,7 @@ var CmdLoginDelete = cli.Command{
}
// RunLoginDelete runs the action of a login delete command
func RunLoginDelete(ctx *cli.Context) error {
func RunLoginDelete(_ context.Context, cmd *cli.Command) error {
logins, err := config.GetLogins()
if err != nil {
log.Fatal(err)
@ -31,8 +32,8 @@ func RunLoginDelete(ctx *cli.Context) error {
var name string
if len(ctx.Args().First()) != 0 {
name = ctx.Args().First()
if len(cmd.Args().First()) != 0 {
name = cmd.Args().First()
} else if len(logins) == 1 {
name = logins[0].Name
} else {

View File

@ -4,6 +4,7 @@
package login
import (
"context"
"log"
"os"
"os/exec"
@ -12,7 +13,7 @@ import (
"code.gitea.io/tea/modules/config"
"github.com/skratchdot/open-golang/open"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLoginEdit represents to login a gitea server.
@ -26,7 +27,7 @@ var CmdLoginEdit = cli.Command{
Flags: []cli.Flag{&flags.OutputFlag},
}
func runLoginEdit(_ *cli.Context) error {
func runLoginEdit(_ context.Context, _ *cli.Command) error {
if e, ok := os.LookupEnv("EDITOR"); ok && e != "" {
cmd := exec.Command(e, config.GetConfigPath())
cmd.Stdin = os.Stdin

View File

@ -5,6 +5,7 @@ package login
import (
"bufio"
"context"
"fmt"
"log"
"net/url"
@ -15,7 +16,7 @@ import (
"code.gitea.io/tea/modules/auth"
"code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/task"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLoginHelper represents to login a gitea helper.
@ -25,19 +26,19 @@ var CmdLoginHelper = cli.Command{
Usage: "Git helper",
Description: `Git helper`,
Hidden: true,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
{
Name: "store",
Description: "Command drops",
Aliases: []string{"erase"},
Action: func(ctx *cli.Context) error {
Action: func(_ context.Context, _ *cli.Command) error {
return nil
},
},
{
Name: "setup",
Description: "Setup helper to tea authenticate",
Action: func(ctx *cli.Context) error {
Action: func(_ context.Context, _ *cli.Command) error {
logins, err := config.GetLogins()
if err != nil {
return err
@ -58,7 +59,7 @@ var CmdLoginHelper = cli.Command{
{
Name: "get",
Description: "Get token to auth",
Action: func(cmd *cli.Context) error {
Action: func(_ context.Context, cmd *cli.Command) error {
wants := map[string]string{}
s := bufio.NewScanner(os.Stdin)
for s.Scan() {

View File

@ -4,11 +4,13 @@
package login
import (
"context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/print"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLoginList represents to login a gitea server.
@ -23,7 +25,7 @@ var CmdLoginList = cli.Command{
}
// RunLoginList list all logins
func RunLoginList(cmd *cli.Context) error {
func RunLoginList(_ context.Context, cmd *cli.Command) error {
logins, err := config.GetLogins()
if err != nil {
return err

View File

@ -4,12 +4,13 @@
package login
import (
"context"
"fmt"
"code.gitea.io/tea/modules/auth"
"code.gitea.io/tea/modules/config"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLoginOAuthRefresh represents a command to refresh an OAuth token
@ -21,12 +22,12 @@ var CmdLoginOAuthRefresh = cli.Command{
Action: runLoginOAuthRefresh,
}
func runLoginOAuthRefresh(ctx *cli.Context) error {
func runLoginOAuthRefresh(_ context.Context, cmd *cli.Command) error {
var loginName string
// Get login name from args or use default
if ctx.Args().Len() > 0 {
loginName = ctx.Args().First()
if cmd.Args().Len() > 0 {
loginName = cmd.Args().First()
} else {
// Get default login
login, err := config.GetDefaultLogin()

View File

@ -6,7 +6,7 @@ package cmd
import (
"code.gitea.io/tea/cmd/login"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdLogout represents to logout a gitea server.

View File

@ -4,11 +4,12 @@
package cmd
import (
stdctx "context"
"code.gitea.io/tea/cmd/milestones"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdMilestones represents to operate repositories milestones.
@ -20,7 +21,7 @@ var CmdMilestones = cli.Command{
Description: `List and create milestones`,
ArgsUsage: "[<milestone name>]",
Action: runMilestones,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&milestones.CmdMilestonesList,
&milestones.CmdMilestonesCreate,
&milestones.CmdMilestonesClose,
@ -31,14 +32,14 @@ var CmdMilestones = cli.Command{
Flags: milestones.CmdMilestonesList.Flags,
}
func runMilestones(ctx *cli.Context) error {
if ctx.Args().Len() == 1 {
return runMilestoneDetail(ctx, ctx.Args().First())
func runMilestones(ctx stdctx.Context, cmd *cli.Command) error {
if cmd.Args().Len() == 1 {
return runMilestoneDetail(ctx, cmd, cmd.Args().First())
}
return milestones.RunMilestonesList(ctx)
return milestones.RunMilestonesList(ctx, cmd)
}
func runMilestoneDetail(cmd *cli.Context, name string) error {
func runMilestoneDetail(_ stdctx.Context, cmd *cli.Command, name string) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -4,9 +4,10 @@
package milestones
import (
"code.gitea.io/tea/cmd/flags"
"context"
"github.com/urfave/cli/v2"
"code.gitea.io/tea/cmd/flags"
"github.com/urfave/cli/v3"
)
// CmdMilestonesClose represents a sub command of milestones to close an milestone
@ -15,11 +16,11 @@ var CmdMilestonesClose = cli.Command{
Usage: "Change state of one or more milestones to 'closed'",
Description: `Change state of one or more milestones to 'closed'`,
ArgsUsage: "<milestone name> [<milestone name>...]",
Action: func(ctx *cli.Context) error {
if ctx.Bool("force") {
return deleteMilestone(ctx)
Action: func(ctx context.Context, cmd *cli.Command) error {
if cmd.Bool("force") {
return deleteMilestone(ctx, cmd)
}
return editMilestoneStatus(ctx, true)
return editMilestoneStatus(ctx, cmd, true)
},
Flags: append([]cli.Flag{
&cli.BoolFlag{

View File

@ -6,14 +6,15 @@ package milestones
import (
"time"
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"code.gitea.io/sdk/gitea"
"github.com/araddon/dateparse"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdMilestonesCreate represents a sub command of milestones to create milestone
@ -48,7 +49,7 @@ var CmdMilestonesCreate = cli.Command{
}, flags.AllDefaultFlags...),
}
func runMilestonesCreate(cmd *cli.Context) error {
func runMilestonesCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
date := ctx.String("deadline")

View File

@ -4,10 +4,12 @@
package milestones
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdMilestonesDelete represents a sub command of milestones to delete an milestone
@ -21,7 +23,7 @@ var CmdMilestonesDelete = cli.Command{
Flags: flags.AllDefaultFlags,
}
func deleteMilestone(cmd *cli.Context) error {
func deleteMilestone(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -6,13 +6,14 @@ package milestones
import (
"fmt"
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
var msIssuesFieldsFlag = flags.FieldsFlag(print.IssueFields, []string{
@ -27,7 +28,7 @@ var CmdMilestonesIssues = cli.Command{
Description: "manage issue/pull of an milestone",
ArgsUsage: "<milestone name>",
Action: runMilestoneIssueList,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&CmdMilestoneAddIssue,
&CmdMilestoneRemoveIssue,
},
@ -69,7 +70,7 @@ var CmdMilestoneRemoveIssue = cli.Command{
Flags: flags.AllDefaultFlags,
}
func runMilestoneIssueList(cmd *cli.Context) error {
func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()
@ -119,7 +120,7 @@ func runMilestoneIssueList(cmd *cli.Context) error {
return nil
}
func runMilestoneIssueAdd(cmd *cli.Context) error {
func runMilestoneIssueAdd(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()
@ -146,7 +147,7 @@ func runMilestoneIssueAdd(cmd *cli.Context) error {
return err
}
func runMilestoneIssueRemove(cmd *cli.Context) error {
func runMilestoneIssueRemove(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -4,12 +4,14 @@
package milestones
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
var fieldsFlag = flags.FieldsFlag(print.MilestoneFields, []string{
@ -37,7 +39,7 @@ var CmdMilestonesList = cli.Command{
}
// RunMilestonesList list milestones
func RunMilestonesList(cmd *cli.Context) error {
func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,6 +4,7 @@
package milestones
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
@ -11,7 +12,7 @@ import (
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdMilestonesReopen represents a sub command of milestones to open an milestone
@ -21,13 +22,13 @@ var CmdMilestonesReopen = cli.Command{
Usage: "Change state of one or more milestones to 'open'",
Description: `Change state of one or more milestones to 'open'`,
ArgsUsage: "<milestone name> [<milestone name> ...]",
Action: func(ctx *cli.Context) error {
return editMilestoneStatus(ctx, false)
Action: func(ctx stdctx.Context, cmd *cli.Command) error {
return editMilestoneStatus(ctx, cmd, false)
},
Flags: flags.AllDefaultFlags,
}
func editMilestoneStatus(cmd *cli.Context, close bool) error {
func editMilestoneStatus(_ stdctx.Context, cmd *cli.Command, close bool) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.Args().Len() == 0 {

View File

@ -6,7 +6,7 @@ package cmd
import (
"code.gitea.io/tea/cmd/notifications"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdNotifications is the main command to operate with notifications
@ -17,7 +17,7 @@ var CmdNotifications = cli.Command{
Usage: "Show notifications",
Description: "Show notifications, by default based on the current repo if available",
Action: notifications.RunNotificationsList,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&notifications.CmdNotificationsList,
&notifications.CmdNotificationsMarkRead,
&notifications.CmdNotificationsMarkUnread,

View File

@ -4,6 +4,7 @@
package notifications
import (
stdctx "context"
"log"
"code.gitea.io/tea/cmd/flags"
@ -11,7 +12,7 @@ import (
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
var notifyFieldsFlag = flags.FieldsFlag(print.NotificationFields, []string{
@ -36,9 +37,9 @@ var CmdNotificationsList = cli.Command{
}
// RunNotificationsList list notifications
func RunNotificationsList(ctx *cli.Context) error {
func RunNotificationsList(ctx stdctx.Context, cmd *cli.Command) error {
var states []gitea.NotifyStatus
statesStr, err := flags.NotificationStateFlag.GetValues(ctx)
statesStr, err := flags.NotificationStateFlag.GetValues(cmd)
if err != nil {
return err
}
@ -47,7 +48,7 @@ func RunNotificationsList(ctx *cli.Context) error {
}
var types []gitea.NotifySubjectType
typesStr, err := notifyTypeFlag.GetValues(ctx)
typesStr, err := notifyTypeFlag.GetValues(cmd)
if err != nil {
return err
}
@ -55,11 +56,11 @@ func RunNotificationsList(ctx *cli.Context) error {
types = append(types, gitea.NotifySubjectType(t))
}
return listNotifications(ctx, states, types)
return listNotifications(ctx, cmd, states, types)
}
// listNotifications will get the notifications based on status and subject type
func listNotifications(cmd *cli.Context, status []gitea.NotifyStatus, subjects []gitea.NotifySubjectType) error {
func listNotifications(_ stdctx.Context, cmd *cli.Command, status []gitea.NotifyStatus, subjects []gitea.NotifySubjectType) error {
var news []*gitea.NotificationThread
var err error

View File

@ -4,13 +4,14 @@
package notifications
import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdNotificationsMarkRead represents a sub command of notifications to list read notifications
@ -21,16 +22,16 @@ var CmdNotificationsMarkRead = cli.Command{
Description: "Mark all filtered or a specific notification as read",
ArgsUsage: "[all | <notification id>]",
Flags: flags.NotificationFlags,
Action: func(ctx *cli.Context) error {
cmd := context.InitCommand(ctx)
filter, err := flags.NotificationStateFlag.GetValues(ctx)
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
filter, err := flags.NotificationStateFlag.GetValues(cmd)
if err != nil {
return err
}
if !cmd.IsSet(flags.NotificationStateFlag.Name) {
if !ctx.IsSet(flags.NotificationStateFlag.Name) {
filter = []string{string(gitea.NotifyStatusUnread)}
}
return markNotificationAs(cmd, filter, gitea.NotifyStatusRead)
return markNotificationAs(ctx, filter, gitea.NotifyStatusRead)
},
}
@ -42,16 +43,16 @@ var CmdNotificationsMarkUnread = cli.Command{
Description: "Mark all filtered or a specific notification as unread",
ArgsUsage: "[all | <notification id>]",
Flags: flags.NotificationFlags,
Action: func(ctx *cli.Context) error {
cmd := context.InitCommand(ctx)
filter, err := flags.NotificationStateFlag.GetValues(ctx)
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
filter, err := flags.NotificationStateFlag.GetValues(cmd)
if err != nil {
return err
}
if !cmd.IsSet(flags.NotificationStateFlag.Name) {
if !ctx.IsSet(flags.NotificationStateFlag.Name) {
filter = []string{string(gitea.NotifyStatusRead)}
}
return markNotificationAs(cmd, filter, gitea.NotifyStatusUnread)
return markNotificationAs(ctx, filter, gitea.NotifyStatusUnread)
},
}
@ -63,16 +64,16 @@ var CmdNotificationsMarkPinned = cli.Command{
Description: "Mark all filtered or a specific notification as pinned",
ArgsUsage: "[all | <notification id>]",
Flags: flags.NotificationFlags,
Action: func(ctx *cli.Context) error {
cmd := context.InitCommand(ctx)
filter, err := flags.NotificationStateFlag.GetValues(ctx)
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
filter, err := flags.NotificationStateFlag.GetValues(cmd)
if err != nil {
return err
}
if !cmd.IsSet(flags.NotificationStateFlag.Name) {
if !ctx.IsSet(flags.NotificationStateFlag.Name) {
filter = []string{string(gitea.NotifyStatusUnread)}
}
return markNotificationAs(cmd, filter, gitea.NotifyStatusPinned)
return markNotificationAs(ctx, filter, gitea.NotifyStatusPinned)
},
}
@ -83,11 +84,11 @@ var CmdNotificationsUnpin = cli.Command{
Description: "Marks all pinned or a specific notification as read",
ArgsUsage: "[all | <notification id>]",
Flags: flags.NotificationFlags,
Action: func(ctx *cli.Context) error {
cmd := context.InitCommand(ctx)
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
filter := []string{string(gitea.NotifyStatusPinned)}
// NOTE: we implicitly mark it as read, to match web UI semantics. marking as unread might be more useful?
return markNotificationAs(cmd, filter, gitea.NotifyStatusRead)
return markNotificationAs(ctx, filter, gitea.NotifyStatusRead)
},
}

View File

@ -4,6 +4,7 @@
package cmd
import (
stdctx "context"
"path"
"strings"
@ -12,7 +13,7 @@ import (
local_git "code.gitea.io/tea/modules/git"
"github.com/skratchdot/open-golang/open"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdOpen represents a sub command of issues to open issue on the web browser
@ -26,7 +27,7 @@ var CmdOpen = cli.Command{
Flags: append([]cli.Flag{}, flags.LoginRepoFlags...),
}
func runOpen(cmd *cli.Context) error {
func runOpen(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,11 +4,13 @@
package cmd
import (
stdctx "context"
"code.gitea.io/tea/cmd/organizations"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdOrgs represents handle organization
@ -20,7 +22,7 @@ var CmdOrgs = cli.Command{
Description: "Show organization details",
ArgsUsage: "[<organization>]",
Action: runOrganizations,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&organizations.CmdOrganizationList,
&organizations.CmdOrganizationCreate,
&organizations.CmdOrganizationDelete,
@ -28,12 +30,12 @@ var CmdOrgs = cli.Command{
Flags: organizations.CmdOrganizationList.Flags,
}
func runOrganizations(cmd *cli.Context) error {
ctx := context.InitCommand(cmd)
if ctx.Args().Len() == 1 {
return runOrganizationDetail(ctx)
func runOrganizations(ctx stdctx.Context, cmd *cli.Command) error {
teaCtx := context.InitCommand(cmd)
if teaCtx.Args().Len() == 1 {
return runOrganizationDetail(teaCtx)
}
return organizations.RunOrganizationList(cmd)
return organizations.RunOrganizationList(ctx, cmd)
}
func runOrganizationDetail(ctx *context.TeaContext) error {

View File

@ -6,12 +6,13 @@ package organizations
import (
"fmt"
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdOrganizationCreate represents a sub command of organizations to delete a given user organization
@ -51,7 +52,7 @@ var CmdOrganizationCreate = cli.Command{
}
// RunOrganizationCreate sets up a new organization
func RunOrganizationCreate(cmd *cli.Context) error {
func RunOrganizationCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
if ctx.Args().Len() < 1 {

View File

@ -4,11 +4,12 @@
package organizations
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdOrganizationDelete represents a sub command of organizations to delete a given user organization
@ -26,7 +27,7 @@ var CmdOrganizationDelete = cli.Command{
}
// RunOrganizationDelete delete user organization
func RunOrganizationDelete(cmd *cli.Context) error {
func RunOrganizationDelete(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()

View File

@ -4,12 +4,13 @@
package organizations
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdOrganizationList represents a sub command of organizations to list users organizations
@ -27,7 +28,7 @@ var CmdOrganizationList = cli.Command{
}
// RunOrganizationList list user organizations
func RunOrganizationList(cmd *cli.Context) error {
func RunOrganizationList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()

View File

@ -4,6 +4,7 @@
package cmd
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/pulls"
@ -14,7 +15,7 @@ import (
"code.gitea.io/tea/modules/workaround"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdPulls is the main command to operate on PRs
@ -32,7 +33,7 @@ var CmdPulls = cli.Command{
Usage: "Whether to display comments (will prompt if not provided & run interactively)",
},
}, pulls.CmdPullsList.Flags...),
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&pulls.CmdPullsList,
&pulls.CmdPullsCheckout,
&pulls.CmdPullsClean,
@ -46,14 +47,14 @@ var CmdPulls = cli.Command{
},
}
func runPulls(ctx *cli.Context) error {
if ctx.Args().Len() == 1 {
return runPullDetail(ctx, ctx.Args().First())
func runPulls(ctx stdctx.Context, cmd *cli.Command) error {
if cmd.Args().Len() == 1 {
return runPullDetail(ctx, cmd, cmd.Args().First())
}
return pulls.RunPullsList(ctx)
return pulls.RunPullsList(ctx, cmd)
}
func runPullDetail(cmd *cli.Context, index string) error {
func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
idx, err := utils.ArgToIndex(index)

View File

@ -7,13 +7,14 @@ import (
"fmt"
"strings"
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdPullsApprove approves a PR
@ -23,7 +24,7 @@ var CmdPullsApprove = cli.Command{
Usage: "Approve a pull request",
Description: "Approve a pull request",
ArgsUsage: "<pull index> [<comment>]",
Action: func(cmd *cli.Context) error {
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,6 +4,7 @@
package pulls
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
@ -12,7 +13,7 @@ import (
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdPullsCheckout is a command to locally checkout the given PR
@ -32,7 +33,7 @@ var CmdPullsCheckout = cli.Command{
}, flags.AllDefaultFlags...),
}
func runPullsCheckout(cmd *cli.Context) error {
func runPullsCheckout(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{
LocalRepo: true,

View File

@ -6,13 +6,14 @@ package pulls
import (
"fmt"
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdPullsClean removes the remote and local feature branches, if a PR is merged.
@ -30,7 +31,7 @@ var CmdPullsClean = cli.Command{
}, flags.AllDefaultFlags...),
}
func runPullsClean(cmd *cli.Context) error {
func runPullsClean(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{LocalRepo: true})
if ctx.Args().Len() != 1 {

View File

@ -4,10 +4,12 @@
package pulls
import (
"context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdPullsClose closes a given open pull request
@ -16,9 +18,9 @@ var CmdPullsClose = cli.Command{
Usage: "Change state of one or more pull requests to 'closed'",
Description: `Change state of one or more pull requests to 'closed'`,
ArgsUsage: "<pull index> [<pull index>...]",
Action: func(ctx *cli.Context) error {
Action: func(ctx context.Context, cmd *cli.Command) error {
var s = gitea.StateClosed
return editPullState(ctx, gitea.EditPullRequestOption{State: &s})
return editPullState(ctx, cmd, gitea.EditPullRequestOption{State: &s})
},
Flags: flags.AllDefaultFlags,
}

View File

@ -4,12 +4,13 @@
package pulls
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdPullsCreate creates a pull request
@ -38,7 +39,7 @@ var CmdPullsCreate = cli.Command{
}, flags.IssuePRCreateFlags...),
}
func runPullsCreate(cmd *cli.Context) error {
func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
// no args -> interactive mode

View File

@ -4,6 +4,7 @@
package pulls
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/modules/context"
@ -11,11 +12,11 @@ import (
"code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// editPullState abstracts the arg parsing to edit the given pull request
func editPullState(cmd *cli.Context, opts gitea.EditPullRequestOption) error {
func editPullState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditPullRequestOption) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.Args().Len() == 0 {

View File

@ -4,12 +4,13 @@
package pulls
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
var pullFieldsFlag = flags.FieldsFlag(print.PullFields, []string{
@ -28,7 +29,7 @@ var CmdPullsList = cli.Command{
}
// RunPullsList return list of pulls
func RunPullsList(cmd *cli.Context) error {
func RunPullsList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,14 +4,15 @@
package pulls
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdPullsMerge merges a PR
@ -39,7 +40,7 @@ var CmdPullsMerge = cli.Command{
Usage: "Merge commit message",
},
}, flags.AllDefaultFlags...),
Action: func(cmd *cli.Context) error {
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,6 +4,7 @@
package pulls
import (
stdctx "context"
"fmt"
"strings"
@ -13,7 +14,7 @@ import (
"code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdPullsReject requests changes to a PR
@ -22,7 +23,7 @@ var CmdPullsReject = cli.Command{
Usage: "Request changes to a pull request",
Description: "Request changes to a pull request",
ArgsUsage: "<pull index> <reason>",
Action: func(cmd *cli.Context) error {
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,10 +4,12 @@
package pulls
import (
"context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdPullsReopen reopens a given closed pull request
@ -17,9 +19,9 @@ var CmdPullsReopen = cli.Command{
Usage: "Change state of one or more pull requests to 'open'",
Description: `Change state of one or more pull requests to 'open'`,
ArgsUsage: "<pull index> [<pull index>...]",
Action: func(ctx *cli.Context) error {
Action: func(ctx context.Context, cmd *cli.Command) error {
var s = gitea.StateOpen
return editPullState(ctx, gitea.EditPullRequestOption{State: &s})
return editPullState(ctx, cmd, gitea.EditPullRequestOption{State: &s})
},
Flags: flags.AllDefaultFlags,
}

View File

@ -4,6 +4,7 @@
package pulls
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
@ -11,7 +12,7 @@ import (
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdPullsReview starts an interactive review session
@ -20,7 +21,7 @@ var CmdPullsReview = cli.Command{
Usage: "Interactively review a pull request",
Description: "Interactively review a pull request",
ArgsUsage: "<pull index>",
Action: func(cmd *cli.Context) error {
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -7,7 +7,7 @@ import (
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/cmd/releases"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdReleases represents to login a gitea server.
@ -20,7 +20,7 @@ var CmdReleases = cli.Command{
Description: "Manage releases",
ArgsUsage: " ", // command does not accept arguments
Action: releases.RunReleasesList,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&releases.CmdReleaseList,
&releases.CmdReleaseCreate,
&releases.CmdReleaseDelete,

View File

@ -4,6 +4,7 @@
package releases
import (
stdctx "context"
"fmt"
"net/http"
"os"
@ -13,7 +14,7 @@ import (
"code.gitea.io/tea/modules/context"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdReleaseCreate represents a sub command of Release to create release
@ -66,7 +67,7 @@ var CmdReleaseCreate = cli.Command{
}, flags.AllDefaultFlags...),
}
func runReleaseCreate(cmd *cli.Context) error {
func runReleaseCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,12 +4,13 @@
package releases
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdReleaseDelete represents a sub command of Release to delete a release
@ -33,7 +34,7 @@ var CmdReleaseDelete = cli.Command{
}, flags.AllDefaultFlags...),
}
func runReleaseDelete(cmd *cli.Context) error {
func runReleaseDelete(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -7,11 +7,12 @@ import (
"fmt"
"strings"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
stdctx "context"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"github.com/urfave/cli/v3"
)
// CmdReleaseEdit represents a sub command of Release to edit releases
@ -56,7 +57,7 @@ var CmdReleaseEdit = cli.Command{
}, flags.AllDefaultFlags...),
}
func runReleaseEdit(cmd *cli.Context) error {
func runReleaseEdit(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -4,6 +4,7 @@
package releases
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
@ -11,7 +12,7 @@ import (
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdReleaseList represents a sub command of Release to list releases
@ -29,7 +30,7 @@ var CmdReleaseList = cli.Command{
}
// RunReleasesList list releases
func RunReleasesList(cmd *cli.Context) error {
func RunReleasesList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,13 +4,15 @@
package cmd
import (
stdctx "context"
"code.gitea.io/tea/cmd/repos"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdRepos represents to login a gitea server.
@ -22,7 +24,7 @@ var CmdRepos = cli.Command{
Description: "Show repository details",
ArgsUsage: "[<repo owner>/<repo name>]",
Action: runRepos,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&repos.CmdReposList,
&repos.CmdReposSearch,
&repos.CmdRepoCreate,
@ -34,14 +36,14 @@ var CmdRepos = cli.Command{
Flags: repos.CmdReposListFlags,
}
func runRepos(ctx *cli.Context) error {
if ctx.Args().Len() == 1 {
return runRepoDetail(ctx, ctx.Args().First())
func runRepos(ctx stdctx.Context, cmd *cli.Command) error {
if cmd.Args().Len() == 1 {
return runRepoDetail(ctx, cmd, cmd.Args().First())
}
return repos.RunReposList(ctx)
return repos.RunReposList(ctx, cmd)
}
func runRepoDetail(cmd *cli.Context, path string) error {
func runRepoDetail(_ stdctx.Context, cmd *cli.Command, path string) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()
repoOwner, repoName := utils.GetOwnerAndRepo(path, ctx.Owner)

View File

@ -4,6 +4,7 @@
package repos
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
@ -11,7 +12,7 @@ import (
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdRepoCreate represents a sub command of repos to create one
@ -90,7 +91,7 @@ var CmdRepoCreate = cli.Command{
}, flags.LoginOutputFlags...),
}
func runRepoCreate(cmd *cli.Context) error {
func runRepoCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()
var (

View File

@ -6,13 +6,14 @@ package repos
import (
"fmt"
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdRepoCreateFromTemplate represents a sub command of repos to generate one from a template repo
@ -81,7 +82,7 @@ var CmdRepoCreateFromTemplate = cli.Command{
}, flags.LoginOutputFlags...),
}
func runRepoCreateFromTemplate(cmd *cli.Context) error {
func runRepoCreateFromTemplate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()

View File

@ -4,13 +4,14 @@
package repos
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdRepoRm represents a sub command of repos to delete an existing repo
@ -44,7 +45,7 @@ var CmdRepoRm = cli.Command{
}, flags.LoginOutputFlags...),
}
func runRepoDelete(cmd *cli.Context) error {
func runRepoDelete(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()

View File

@ -7,7 +7,7 @@ import (
"fmt"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
var typeFilterFlag = cli.StringFlag{
@ -17,8 +17,8 @@ var typeFilterFlag = cli.StringFlag{
Usage: "Filter by type: fork, mirror, source",
}
func getTypeFilter(ctx *cli.Context) (filter gitea.RepoType, err error) {
t := ctx.String("type")
func getTypeFilter(cmd *cli.Command) (filter gitea.RepoType, err error) {
t := cmd.String("type")
filter = gitea.RepoTypeNone
switch t {
case "":

View File

@ -4,6 +4,7 @@
package repos
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
@ -11,7 +12,7 @@ import (
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdRepoFork represents a sub command of repos to fork an existing repo
@ -31,7 +32,7 @@ var CmdRepoFork = cli.Command{
}, flags.LoginRepoFlags...),
}
func runRepoFork(cmd *cli.Context) error {
func runRepoFork(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -4,12 +4,14 @@
package repos
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
var repoFieldsFlag = flags.FieldsFlag(print.RepoFields, []string{
@ -47,9 +49,9 @@ var CmdReposList = cli.Command{
}
// RunReposList list repositories
func RunReposList(cmd *cli.Context) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()
func RunReposList(_ stdctx.Context, cmd *cli.Command) error {
teaCmd := context.InitCommand(cmd)
client := teaCmd.Login.Client()
typeFilter, err := getTypeFilter(cmd)
if err != nil {
@ -57,20 +59,20 @@ func RunReposList(cmd *cli.Context) error {
}
var rps []*gitea.Repository
if ctx.Bool("starred") {
if teaCmd.Bool("starred") {
user, _, err := client.GetMyUserInfo()
if err != nil {
return err
}
rps, _, err = client.SearchRepos(gitea.SearchRepoOptions{
ListOptions: ctx.GetListOptions(),
ListOptions: teaCmd.GetListOptions(),
StarredByUserID: user.ID,
})
} else if ctx.Bool("watched") {
} else if teaCmd.Bool("watched") {
rps, _, err = client.GetMyWatchedRepos() // TODO: this does not expose pagination..
} else {
rps, _, err = client.ListMyRepos(gitea.ListReposOptions{
ListOptions: ctx.GetListOptions(),
ListOptions: teaCmd.GetListOptions(),
})
}
@ -88,7 +90,7 @@ func RunReposList(cmd *cli.Context) error {
return err
}
print.ReposList(reposFiltered, ctx.Output, fields)
print.ReposList(reposFiltered, teaCmd.Output, fields)
return nil
}

View File

@ -6,12 +6,13 @@ package repos
import (
"fmt"
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdRepoMigrate represents a sub command of repos to migrate one
@ -107,7 +108,7 @@ var CmdRepoMigrate = cli.Command{
}, flags.LoginOutputFlags...),
}
func runRepoMigrate(cmd *cli.Context) error {
func runRepoMigrate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()
var (

View File

@ -4,6 +4,7 @@
package repos
import (
stdctx "context"
"fmt"
"strings"
@ -12,7 +13,7 @@ import (
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdReposSearch represents a sub command of repos to find them
@ -55,14 +56,14 @@ var CmdReposSearch = cli.Command{
}, flags.LoginOutputFlags...),
}
func runReposSearch(cmd *cli.Context) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()
func runReposSearch(_ stdctx.Context, cmd *cli.Command) error {
teaCmd := context.InitCommand(cmd)
client := teaCmd.Login.Client()
var ownerID int64
if ctx.IsSet("owner") {
if teaCmd.IsSet("owner") {
// test if owner is a organisation
org, _, err := client.GetOrg(ctx.String("owner"))
org, _, err := client.GetOrg(teaCmd.String("owner"))
if err != nil {
// HACK: the client does not return a response on 404, so we can't check res.StatusCode
if err.Error() != "404 Not Found" {
@ -70,7 +71,7 @@ func runReposSearch(cmd *cli.Context) error {
}
// if owner is no org, its a user
user, _, err := client.GetUserInfo(ctx.String("owner"))
user, _, err := client.GetUserInfo(teaCmd.String("owner"))
if err != nil {
return err
}
@ -81,14 +82,14 @@ func runReposSearch(cmd *cli.Context) error {
}
var isArchived *bool
if ctx.IsSet("archived") {
archived := strings.ToLower(ctx.String("archived"))[:1] == "t"
if teaCmd.IsSet("archived") {
archived := strings.ToLower(teaCmd.String("archived"))[:1] == "t"
isArchived = &archived
}
var isPrivate *bool
if ctx.IsSet("private") {
private := strings.ToLower(ctx.String("private"))[:1] == "t"
if teaCmd.IsSet("private") {
private := strings.ToLower(teaCmd.String("private"))[:1] == "t"
isPrivate = &private
}
@ -98,8 +99,8 @@ func runReposSearch(cmd *cli.Context) error {
}
var keyword string
if ctx.Args().Present() {
keyword = strings.Join(ctx.Args().Slice(), " ")
if teaCmd.Args().Present() {
keyword = strings.Join(teaCmd.Args().Slice(), " ")
}
user, _, err := client.GetMyUserInfo()
@ -108,14 +109,14 @@ func runReposSearch(cmd *cli.Context) error {
}
rps, _, err := client.SearchRepos(gitea.SearchRepoOptions{
ListOptions: ctx.GetListOptions(),
ListOptions: teaCmd.GetListOptions(),
OwnerID: ownerID,
IsPrivate: isPrivate,
IsArchived: isArchived,
Type: mode,
Keyword: keyword,
KeywordInDescription: true,
KeywordIsTopic: ctx.Bool("topic"),
KeywordIsTopic: teaCmd.Bool("topic"),
PrioritizedByOwnerID: user.ID,
})
if err != nil {
@ -126,6 +127,6 @@ func runReposSearch(cmd *cli.Context) error {
if err != nil {
return err
}
print.ReposList(rps, ctx.Output, fields)
print.ReposList(rps, teaCmd.Output, fields)
return nil
}

View File

@ -5,7 +5,7 @@ package cmd
import (
"code.gitea.io/tea/cmd/times"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdTrackedTimes represents the command to operate repositories' times.
@ -19,7 +19,7 @@ var CmdTrackedTimes = cli.Command{
times might be listed.`,
ArgsUsage: "[username | #issue]",
Action: times.RunTimesList,
Subcommands: []*cli.Command{
Commands: []*cli.Command{
&times.CmdTrackedTimesAdd,
&times.CmdTrackedTimesDelete,
&times.CmdTrackedTimesReset,

View File

@ -4,6 +4,7 @@
package times
import (
stdctx "context"
"fmt"
"strings"
"time"
@ -13,7 +14,7 @@ import (
"code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdTrackedTimesAdd represents a sub command of times to add time to an issue
@ -30,7 +31,7 @@ var CmdTrackedTimesAdd = cli.Command{
Flags: flags.LoginRepoFlags,
}
func runTrackedTimesAdd(cmd *cli.Context) error {
func runTrackedTimesAdd(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})

View File

@ -4,6 +4,7 @@
package times
import (
stdctx "context"
"fmt"
"strconv"
@ -11,7 +12,7 @@ import (
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdTrackedTimesDelete is a sub command of CmdTrackedTimes, and removes time from an issue
@ -24,7 +25,7 @@ var CmdTrackedTimesDelete = cli.Command{
Flags: flags.LoginRepoFlags,
}
func runTrackedTimesDelete(cmd *cli.Context) error {
func runTrackedTimesDelete(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -4,6 +4,7 @@
package times
import (
stdctx "context"
"fmt"
"strings"
"time"
@ -15,7 +16,7 @@ import (
"code.gitea.io/sdk/gitea"
"github.com/araddon/dateparse"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// NOTE: not using NewCsvFlag, as we don't want an alias & default value.
@ -68,7 +69,7 @@ Depending on your permissions on the repository, only your own tracked times mig
}
// RunTimesList list repositories
func RunTimesList(cmd *cli.Context) error {
func RunTimesList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -4,13 +4,14 @@
package times
import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdTrackedTimesReset is a subcommand of CmdTrackedTimes, and
@ -23,7 +24,7 @@ var CmdTrackedTimesReset = cli.Command{
Flags: flags.LoginRepoFlags,
}
func runTrackedTimesReset(cmd *cli.Context) error {
func runTrackedTimesReset(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()

View File

@ -4,10 +4,11 @@
package cmd
import (
stdctx "context"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
// CmdWhoami represents the command to show current logged in user
@ -17,7 +18,7 @@ var CmdWhoami = cli.Command{
Description: `For debugging purposes, show the user that is currently logged in.`,
Usage: "Show current logged in user",
ArgsUsage: " ", // command does not accept arguments
Action: func(cmd *cli.Context) error {
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
client := ctx.Login.Client()
user, _, _ := client.GetMyUserInfo()