mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-03 02:18:30 +02:00
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:
@ -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 (
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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 "":
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 (
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user