mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-30 16:55:25 +01:00 
			
		
		
		
	When there is no login detected, list all possible logins to select
This commit is contained in:
		| @@ -7,7 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/tea/cmd/admin/users" | 	"code.gitea.io/tea/cmd/admin/users" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| ) | ) | ||||||
| @@ -44,7 +44,7 @@ var cmdAdminUsers = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runAdminUserDetail(_ stdctx.Context, cmd *cli.Command, u string) error { | func runAdminUserDetail(_ stdctx.Context, cmd *cli.Command, u string) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
| 	user, _, err := client.GetUserInfo(u) | 	user, _, err := client.GetUserInfo(u) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
| @@ -6,8 +6,8 @@ package users | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
| @@ -34,7 +34,7 @@ var CmdUserList = cli.Command{ | |||||||
|  |  | ||||||
| // RunUserList list users | // RunUserList list users | ||||||
| func RunUserList(_ stdctx.Context, cmd *cli.Command) error { | func RunUserList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
|  |  | ||||||
| 	fields, err := userFieldsFlag.GetValues(cmd) | 	fields, err := userFieldsFlag.GetValues(cmd) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
| @@ -9,6 +9,7 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
|  |  | ||||||
| @@ -27,7 +28,7 @@ var CmdReleaseAttachmentCreate = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runReleaseAttachmentCreate(_ stdctx.Context, cmd *cli.Command) error { | func runReleaseAttachmentCreate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
|  |  | ||||||
| @@ -32,7 +33,7 @@ var CmdReleaseAttachmentDelete = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runReleaseAttachmentDelete(_ stdctx.Context, cmd *cli.Command) error { | func runReleaseAttachmentDelete(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -31,7 +32,7 @@ var CmdReleaseAttachmentList = cli.Command{ | |||||||
|  |  | ||||||
| // RunReleaseAttachmentList list release attachments | // RunReleaseAttachmentList list release attachments | ||||||
| func RunReleaseAttachmentList(_ stdctx.Context, cmd *cli.Command) error { | func RunReleaseAttachmentList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										105
									
								
								cmd/base/command.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								cmd/base/command.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | |||||||
|  | // Copyright 2025 The Gitea Authors. All rights reserved. | ||||||
|  | // SPDX-License-Identifier: MIT | ||||||
|  |  | ||||||
|  | package base | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"log" | ||||||
|  | 	"os" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/modules/config" | ||||||
|  | 	"code.gitea.io/tea/modules/context" | ||||||
|  | 	"code.gitea.io/tea/modules/interact" | ||||||
|  | 	"code.gitea.io/tea/modules/utils" | ||||||
|  |  | ||||||
|  | 	gogit "github.com/go-git/go-git/v5" | ||||||
|  | 	"github.com/urfave/cli/v3" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | // InitCommand resolves the application context, and returns the active login, and if | ||||||
|  | // available the repo slug. It does this by reading the config file for logins, parsing | ||||||
|  | // the remotes of the .git repo specified in repoFlag or $PWD, and using overrides from | ||||||
|  | // command flags. If a local git repo can't be found, repo slug values are unset. | ||||||
|  | func InitCommand(cmd *cli.Command) *context.TeaContext { | ||||||
|  | 	// these flags are used as overrides to the context detection via local git repo | ||||||
|  | 	repoFlag := cmd.String("repo") | ||||||
|  | 	loginFlag := cmd.String("login") | ||||||
|  | 	remoteFlag := cmd.String("remote") | ||||||
|  |  | ||||||
|  | 	var ( | ||||||
|  | 		c                  context.TeaContext | ||||||
|  | 		err                error | ||||||
|  | 		repoPath           string // empty means PWD | ||||||
|  | 		repoFlagPathExists bool | ||||||
|  | 	) | ||||||
|  |  | ||||||
|  | 	// check if repoFlag can be interpreted as path to local repo. | ||||||
|  | 	if len(repoFlag) != 0 { | ||||||
|  | 		if repoFlagPathExists, err = utils.DirExists(repoFlag); err != nil { | ||||||
|  | 			log.Fatal(err.Error()) | ||||||
|  | 		} | ||||||
|  | 		if repoFlagPathExists { | ||||||
|  | 			repoPath = repoFlag | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if len(remoteFlag) == 0 { | ||||||
|  | 		remoteFlag = config.GetPreferences().FlagDefaults.Remote | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if repoPath == "" { | ||||||
|  | 		if repoPath, err = os.Getwd(); err != nil { | ||||||
|  | 			log.Fatal(err.Error()) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// try to read local git repo & extract context: if repoFlag specifies a valid path, read repo in that dir, | ||||||
|  | 	// otherwise attempt PWD. if no repo is found, continue with default login | ||||||
|  | 	if c.LocalRepo, c.Login, c.RepoSlug, err = context.ContextFromLocalRepo(repoPath, remoteFlag); err != nil { | ||||||
|  | 		if err == context.ErrNotAGiteaRepo || err == gogit.ErrRepositoryNotExists { | ||||||
|  | 			// we can deal with that, commands needing the optional values use ctx.Ensure() | ||||||
|  | 		} else { | ||||||
|  | 			log.Fatal(err.Error()) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if len(repoFlag) != 0 && !repoFlagPathExists { | ||||||
|  | 		// if repoFlag is not a valid path, use it to override repoSlug | ||||||
|  | 		c.RepoSlug = repoFlag | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// override config user with env variable | ||||||
|  | 	envLogin := context.GetLoginByEnvVar() | ||||||
|  | 	if envLogin != nil { | ||||||
|  | 		_, err := utils.ValidateAuthenticationMethod(envLogin.URL, envLogin.Token, "", "", false, "", "") | ||||||
|  | 		if err != nil { | ||||||
|  | 			log.Fatal(err.Error()) | ||||||
|  | 		} | ||||||
|  | 		c.Login = envLogin | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// override login from flag, or use default login if repo based detection failed | ||||||
|  | 	if len(loginFlag) != 0 { | ||||||
|  | 		c.Login = config.GetLoginByName(loginFlag) | ||||||
|  | 		if c.Login == nil { | ||||||
|  | 			log.Fatalf("Login name '%s' does not exist", loginFlag) | ||||||
|  | 		} | ||||||
|  | 	} else if c.Login == nil { | ||||||
|  | 		c.Login, err = interact.LoginSelect() | ||||||
|  | 		if err != nil { | ||||||
|  | 			// TODO: maybe we can directly start interact.CreateLogin() (only if | ||||||
|  | 			// we're sure we can interactively!), as gh cli does. | ||||||
|  | 			fmt.Println(`No gitea login configured. To start using tea, first run | ||||||
|  |   tea login add | ||||||
|  | and then run your command again.`) | ||||||
|  | 			os.Exit(1) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// parse reposlug (owner falling back to login owner if reposlug contains only repo name) | ||||||
|  | 	c.Owner, c.Repo = utils.GetOwnerAndRepo(c.RepoSlug, c.Login.User) | ||||||
|  | 	c.Command = cmd | ||||||
|  | 	c.Output = cmd.String("output") | ||||||
|  | 	return &c | ||||||
|  | } | ||||||
| @@ -6,6 +6,7 @@ package branches | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -38,7 +39,7 @@ var CmdBranchesList = cli.Command{ | |||||||
|  |  | ||||||
| // RunBranchesList list branches | // RunBranchesList list branches | ||||||
| func RunBranchesList(_ stdctx.Context, cmd *cli.Command) error { | func RunBranchesList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	owner := ctx.Owner | 	owner := ctx.Owner | ||||||
| @@ -52,7 +53,6 @@ func RunBranchesList(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| 	branches, _, err = ctx.Login.Client().ListRepoBranches(owner, ctx.Repo, gitea.ListRepoBranchesOptions{ | 	branches, _, err = ctx.Login.Client().ListRepoBranches(owner, ctx.Repo, gitea.ListRepoBranchesOptions{ | ||||||
| 		ListOptions: flags.GetListOptions(), | 		ListOptions: flags.GetListOptions(), | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @@ -60,7 +60,6 @@ func RunBranchesList(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| 	protections, _, err = ctx.Login.Client().ListBranchProtections(owner, ctx.Repo, gitea.ListBranchProtectionsOptions{ | 	protections, _, err = ctx.Login.Client().ListBranchProtections(owner, ctx.Repo, gitea.ListBranchProtectionsOptions{ | ||||||
| 		ListOptions: flags.GetListOptions(), | 		ListOptions: flags.GetListOptions(), | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
|  |  | ||||||
| @@ -45,7 +46,7 @@ var CmdBranchesUnprotect = cli.Command{ | |||||||
|  |  | ||||||
| // RunBranchesProtect function to protect/unprotect a list of branches | // RunBranchesProtect function to protect/unprotect a list of branches | ||||||
| func RunBranchesProtect(_ stdctx.Context, cmd *cli.Command) error { | func RunBranchesProtect(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	if !cmd.Args().Present() { | 	if !cmd.Args().Present() { | ||||||
|   | |||||||
| @@ -7,9 +7,9 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/config" | 	"code.gitea.io/tea/modules/config" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/debug" | 	"code.gitea.io/tea/modules/debug" | ||||||
| 	"code.gitea.io/tea/modules/git" | 	"code.gitea.io/tea/modules/git" | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| @@ -48,7 +48,7 @@ When a host is specified in the repo-slug, it will override the login specified | |||||||
| } | } | ||||||
|  |  | ||||||
| func runRepoClone(ctx stdctx.Context, cmd *cli.Command) error { | func runRepoClone(ctx stdctx.Context, cmd *cli.Command) error { | ||||||
| 	teaCmd := context.InitCommand(cmd) | 	teaCmd := base.InitCommand(cmd) | ||||||
|  |  | ||||||
| 	args := teaCmd.Args() | 	args := teaCmd.Args() | ||||||
| 	if args.Len() < 1 { | 	if args.Len() < 1 { | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ import ( | |||||||
| 	"io" | 	"io" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/config" | 	"code.gitea.io/tea/modules/config" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| @@ -36,7 +37,7 @@ var CmdAddComment = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runAddComment(_ stdctx.Context, cmd *cli.Command) error { | func runAddComment(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	args := ctx.Args() | 	args := ctx.Args() | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/issues" | 	"code.gitea.io/tea/cmd/issues" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| @@ -48,7 +49,7 @@ func runIssues(ctx stdctx.Context, cmd *cli.Command) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func runIssueDetail(_ stdctx.Context, cmd *cli.Command, index string) error { | func runIssueDetail(_ stdctx.Context, cmd *cli.Command, index string) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	idx, err := utils.ArgToIndex(index) | 	idx, err := utils.ArgToIndex(index) | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -23,7 +24,7 @@ var CmdIssuesClose = cli.Command{ | |||||||
| 	Description: `Change state of one ore more issues to 'closed'`, | 	Description: `Change state of one ore more issues to 'closed'`, | ||||||
| 	ArgsUsage:   "<issue index> [<issue index>...]", | 	ArgsUsage:   "<issue index> [<issue index>...]", | ||||||
| 	Action: func(ctx stdctx.Context, cmd *cli.Command) error { | 	Action: func(ctx stdctx.Context, cmd *cli.Command) error { | ||||||
| 		var s = gitea.StateClosed | 		s := gitea.StateClosed | ||||||
| 		return editIssueState(ctx, cmd, gitea.EditIssueOption{State: &s}) | 		return editIssueState(ctx, cmd, gitea.EditIssueOption{State: &s}) | ||||||
| 	}, | 	}, | ||||||
| 	Flags: flags.AllDefaultFlags, | 	Flags: flags.AllDefaultFlags, | ||||||
| @@ -31,7 +32,7 @@ var CmdIssuesClose = cli.Command{ | |||||||
|  |  | ||||||
| // editIssueState abstracts the arg parsing to edit the given issue | // editIssueState abstracts the arg parsing to edit the given issue | ||||||
| func editIssueState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditIssueOption) error { | func editIssueState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditIssueOption) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	if ctx.Args().Len() == 0 { | 	if ctx.Args().Len() == 0 { | ||||||
| 		return fmt.Errorf(ctx.Command.ArgsUsage) | 		return fmt.Errorf(ctx.Command.ArgsUsage) | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ package issues | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| @@ -26,7 +27,7 @@ var CmdIssuesCreate = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runIssuesCreate(_ stdctx.Context, cmd *cli.Command) error { | func runIssuesCreate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	if ctx.NumFlags() == 0 { | 	if ctx.NumFlags() == 0 { | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import ( | |||||||
|  |  | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| @@ -30,7 +31,7 @@ use an empty string (eg. --milestone "").`, | |||||||
| } | } | ||||||
|  |  | ||||||
| func runIssuesEdit(_ stdctx.Context, cmd *cli.Command) error { | func runIssuesEdit(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	if !cmd.Args().Present() { | 	if !cmd.Args().Present() { | ||||||
|   | |||||||
| @@ -8,8 +8,8 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
| @@ -34,7 +34,7 @@ var CmdIssuesList = cli.Command{ | |||||||
|  |  | ||||||
| // RunIssuesList list issues | // RunIssuesList list issues | ||||||
| func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error { | func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
|  |  | ||||||
| 	state := gitea.StateOpen | 	state := gitea.StateOpen | ||||||
| 	switch ctx.String("state") { | 	switch ctx.String("state") { | ||||||
| @@ -97,7 +97,6 @@ func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| 			Since:       from, | 			Since:       from, | ||||||
| 			Before:      until, | 			Before:      until, | ||||||
| 		}) | 		}) | ||||||
|  |  | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| @@ -116,7 +115,6 @@ func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| 			Before:      until, | 			Before:      until, | ||||||
| 			Owner:       owner, | 			Owner:       owner, | ||||||
| 		}) | 		}) | ||||||
|  |  | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
|  |  | ||||||
| @@ -46,7 +47,7 @@ var CmdLabelCreate = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runLabelCreate(_ stdctx.Context, cmd *cli.Command) error { | func runLabelCreate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	labelFile := ctx.String("file") | 	labelFile := ctx.String("file") | ||||||
| @@ -65,7 +66,7 @@ func runLabelCreate(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| 		defer f.Close() | 		defer f.Close() | ||||||
|  |  | ||||||
| 		scanner := bufio.NewScanner(f) | 		scanner := bufio.NewScanner(f) | ||||||
| 		var i = 1 | 		i := 1 | ||||||
| 		for scanner.Scan() { | 		for scanner.Scan() { | ||||||
| 			line := scanner.Text() | 			line := scanner.Text() | ||||||
| 			color, name, description := splitLabelLine(line) | 			color, name, description := splitLabelLine(line) | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ package labels | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
|  |  | ||||||
| @@ -29,7 +30,7 @@ var CmdLabelDelete = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runLabelDelete(_ stdctx.Context, cmd *cli.Command) error { | func runLabelDelete(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	_, err := ctx.Login.Client().DeleteLabel(ctx.Owner, ctx.Repo, ctx.Int64("id")) | 	_, err := ctx.Login.Client().DeleteLabel(ctx.Owner, ctx.Repo, ctx.Int64("id")) | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ package labels | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -36,7 +37,7 @@ var CmdLabelsList = cli.Command{ | |||||||
|  |  | ||||||
| // RunLabelsList list labels. | // RunLabelsList list labels. | ||||||
| func RunLabelsList(_ stdctx.Context, cmd *cli.Command) error { | func RunLabelsList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ package labels | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
|  |  | ||||||
| @@ -41,7 +42,7 @@ var CmdLabelUpdate = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runLabelUpdate(_ stdctx.Context, cmd *cli.Command) error { | func runLabelUpdate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	id := ctx.Int64("id") | 	id := ctx.Int64("id") | ||||||
| @@ -67,7 +68,6 @@ func runLabelUpdate(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| 		Color:       pColor, | 		Color:       pColor, | ||||||
| 		Description: pDescription, | 		Description: pDescription, | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ package cmd | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/milestones" | 	"code.gitea.io/tea/cmd/milestones" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -40,7 +41,7 @@ func runMilestones(ctx stdctx.Context, cmd *cli.Command) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func runMilestoneDetail(_ stdctx.Context, cmd *cli.Command, name string) error { | func runMilestoneDetail(_ stdctx.Context, cmd *cli.Command, name string) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -9,8 +9,8 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| 	"code.gitea.io/tea/modules/task" | 	"code.gitea.io/tea/modules/task" | ||||||
| 	"github.com/araddon/dateparse" | 	"github.com/araddon/dateparse" | ||||||
| @@ -50,7 +50,7 @@ var CmdMilestonesCreate = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runMilestonesCreate(_ stdctx.Context, cmd *cli.Command) error { | func runMilestonesCreate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
|  |  | ||||||
| 	date := ctx.String("deadline") | 	date := ctx.String("deadline") | ||||||
| 	deadline := &time.Time{} | 	deadline := &time.Time{} | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ package milestones | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
|  |  | ||||||
| @@ -24,7 +25,7 @@ var CmdMilestonesDelete = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func deleteMilestone(_ stdctx.Context, cmd *cli.Command) error { | func deleteMilestone(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -9,6 +9,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -71,7 +72,7 @@ var CmdMilestoneRemoveIssue = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error { | func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
| @@ -121,7 +122,7 @@ func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func runMilestoneIssueAdd(_ stdctx.Context, cmd *cli.Command) error { | func runMilestoneIssueAdd(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
| 	if ctx.Args().Len() != 2 { | 	if ctx.Args().Len() != 2 { | ||||||
| @@ -148,7 +149,7 @@ func runMilestoneIssueAdd(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func runMilestoneIssueRemove(_ stdctx.Context, cmd *cli.Command) error { | func runMilestoneIssueRemove(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
| 	if ctx.Args().Len() != 2 { | 	if ctx.Args().Len() != 2 { | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ package milestones | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -40,7 +41,7 @@ var CmdMilestonesList = cli.Command{ | |||||||
|  |  | ||||||
| // RunMilestonesList list milestones | // RunMilestonesList list milestones | ||||||
| func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error { | func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	fields, err := fieldsFlag.GetValues(cmd) | 	fields, err := fieldsFlag.GetValues(cmd) | ||||||
| @@ -64,7 +65,6 @@ func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| 		ListOptions: flags.GetListOptions(), | 		ListOptions: flags.GetListOptions(), | ||||||
| 		State:       state, | 		State:       state, | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -29,7 +30,7 @@ var CmdMilestonesReopen = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func editMilestoneStatus(_ stdctx.Context, cmd *cli.Command, close bool) error { | func editMilestoneStatus(_ stdctx.Context, cmd *cli.Command, close bool) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	if ctx.Args().Len() == 0 { | 	if ctx.Args().Len() == 0 { | ||||||
| 		return fmt.Errorf(ctx.Command.ArgsUsage) | 		return fmt.Errorf(ctx.Command.ArgsUsage) | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"log" | 	"log" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -64,7 +65,7 @@ func listNotifications(_ stdctx.Context, cmd *cli.Command, status []gitea.Notify | |||||||
| 	var news []*gitea.NotificationThread | 	var news []*gitea.NotificationThread | ||||||
| 	var err error | 	var err error | ||||||
|  |  | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
| 	all := ctx.Bool("mine") | 	all := ctx.Bool("mine") | ||||||
|  |  | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/utils" | 	"code.gitea.io/tea/modules/utils" | ||||||
| @@ -23,7 +24,7 @@ var CmdNotificationsMarkRead = cli.Command{ | |||||||
| 	ArgsUsage:   "[all | <notification id>]", | 	ArgsUsage:   "[all | <notification id>]", | ||||||
| 	Flags:       flags.NotificationFlags, | 	Flags:       flags.NotificationFlags, | ||||||
| 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 		ctx := context.InitCommand(cmd) | 		ctx := base.InitCommand(cmd) | ||||||
| 		filter, err := flags.NotificationStateFlag.GetValues(cmd) | 		filter, err := flags.NotificationStateFlag.GetValues(cmd) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| @@ -44,7 +45,7 @@ var CmdNotificationsMarkUnread = cli.Command{ | |||||||
| 	ArgsUsage:   "[all | <notification id>]", | 	ArgsUsage:   "[all | <notification id>]", | ||||||
| 	Flags:       flags.NotificationFlags, | 	Flags:       flags.NotificationFlags, | ||||||
| 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 		ctx := context.InitCommand(cmd) | 		ctx := base.InitCommand(cmd) | ||||||
| 		filter, err := flags.NotificationStateFlag.GetValues(cmd) | 		filter, err := flags.NotificationStateFlag.GetValues(cmd) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| @@ -65,7 +66,7 @@ var CmdNotificationsMarkPinned = cli.Command{ | |||||||
| 	ArgsUsage:   "[all | <notification id>]", | 	ArgsUsage:   "[all | <notification id>]", | ||||||
| 	Flags:       flags.NotificationFlags, | 	Flags:       flags.NotificationFlags, | ||||||
| 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 		ctx := context.InitCommand(cmd) | 		ctx := base.InitCommand(cmd) | ||||||
| 		filter, err := flags.NotificationStateFlag.GetValues(cmd) | 		filter, err := flags.NotificationStateFlag.GetValues(cmd) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return err | 			return err | ||||||
| @@ -85,7 +86,7 @@ var CmdNotificationsUnpin = cli.Command{ | |||||||
| 	ArgsUsage:   "[all | <notification id>]", | 	ArgsUsage:   "[all | <notification id>]", | ||||||
| 	Flags:       flags.NotificationFlags, | 	Flags:       flags.NotificationFlags, | ||||||
| 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 		ctx := context.InitCommand(cmd) | 		ctx := base.InitCommand(cmd) | ||||||
| 		filter := []string{string(gitea.NotifyStatusPinned)} | 		filter := []string{string(gitea.NotifyStatusPinned)} | ||||||
| 		// NOTE: we implicitly mark it as read, to match web UI semantics. marking as unread might be more useful? | 		// NOTE: we implicitly mark it as read, to match web UI semantics. marking as unread might be more useful? | ||||||
| 		return markNotificationAs(ctx, filter, gitea.NotifyStatusRead) | 		return markNotificationAs(ctx, filter, gitea.NotifyStatusRead) | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import ( | |||||||
| 	"path" | 	"path" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	local_git "code.gitea.io/tea/modules/git" | 	local_git "code.gitea.io/tea/modules/git" | ||||||
| @@ -28,7 +29,7 @@ var CmdOpen = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runOpen(_ stdctx.Context, cmd *cli.Command) error { | func runOpen(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	var suffix string | 	var suffix string | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ package cmd | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/organizations" | 	"code.gitea.io/tea/cmd/organizations" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -31,7 +32,7 @@ var CmdOrgs = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runOrganizations(ctx stdctx.Context, cmd *cli.Command) error { | func runOrganizations(ctx stdctx.Context, cmd *cli.Command) error { | ||||||
| 	teaCtx := context.InitCommand(cmd) | 	teaCtx := base.InitCommand(cmd) | ||||||
| 	if teaCtx.Args().Len() == 1 { | 	if teaCtx.Args().Len() == 1 { | ||||||
| 		return runOrganizationDetail(teaCtx) | 		return runOrganizationDetail(teaCtx) | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -9,8 +9,8 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| ) | ) | ||||||
| @@ -53,7 +53,7 @@ var CmdOrganizationCreate = cli.Command{ | |||||||
|  |  | ||||||
| // RunOrganizationCreate sets up a new organization | // RunOrganizationCreate sets up a new organization | ||||||
| func RunOrganizationCreate(_ stdctx.Context, cmd *cli.Command) error { | func RunOrganizationCreate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
|  |  | ||||||
| 	if ctx.Args().Len() < 1 { | 	if ctx.Args().Len() < 1 { | ||||||
| 		return fmt.Errorf("You have to specify the organization name you want to create") | 		return fmt.Errorf("You have to specify the organization name you want to create") | ||||||
|   | |||||||
| @@ -7,8 +7,8 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -28,7 +28,7 @@ var CmdOrganizationDelete = cli.Command{ | |||||||
|  |  | ||||||
| // RunOrganizationDelete delete user organization | // RunOrganizationDelete delete user organization | ||||||
| func RunOrganizationDelete(_ stdctx.Context, cmd *cli.Command) error { | func RunOrganizationDelete(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
|  |  | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,8 +7,8 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| ) | ) | ||||||
| @@ -29,7 +29,7 @@ var CmdOrganizationList = cli.Command{ | |||||||
|  |  | ||||||
| // RunOrganizationList list user organizations | // RunOrganizationList list user organizations | ||||||
| func RunOrganizationList(_ stdctx.Context, cmd *cli.Command) error { | func RunOrganizationList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
| 	userOrganizations, _, err := client.ListUserOrgs(ctx.Login.User, gitea.ListOrgsOptions{ | 	userOrganizations, _, err := client.ListUserOrgs(ctx.Login.User, gitea.ListOrgsOptions{ | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/pulls" | 	"code.gitea.io/tea/cmd/pulls" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| @@ -55,7 +56,7 @@ func runPulls(ctx stdctx.Context, cmd *cli.Command) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error { | func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	idx, err := utils.ArgToIndex(index) | 	idx, err := utils.ArgToIndex(index) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/task" | 	"code.gitea.io/tea/modules/task" | ||||||
| @@ -25,7 +26,7 @@ var CmdPullsApprove = cli.Command{ | |||||||
| 	Description: "Approve a pull request", | 	Description: "Approve a pull request", | ||||||
| 	ArgsUsage:   "<pull index> [<comment>]", | 	ArgsUsage:   "<pull index> [<comment>]", | ||||||
| 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 		ctx := context.InitCommand(cmd) | 		ctx := base.InitCommand(cmd) | ||||||
| 		ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 		ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 		if ctx.Args().Len() == 0 { | 		if ctx.Args().Len() == 0 { | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| @@ -34,7 +35,7 @@ var CmdPullsCheckout = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runPullsCheckout(_ stdctx.Context, cmd *cli.Command) error { | func runPullsCheckout(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{ | 	ctx.Ensure(context.CtxRequirement{ | ||||||
| 		LocalRepo:  true, | 		LocalRepo:  true, | ||||||
| 		RemoteRepo: true, | 		RemoteRepo: true, | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import ( | |||||||
|  |  | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| @@ -32,7 +33,7 @@ var CmdPullsClean = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runPullsClean(_ stdctx.Context, cmd *cli.Command) error { | func runPullsClean(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{LocalRepo: true}) | 	ctx.Ensure(context.CtxRequirement{LocalRepo: true}) | ||||||
| 	if ctx.Args().Len() != 1 { | 	if ctx.Args().Len() != 1 { | ||||||
| 		return fmt.Errorf("Must specify a PR index") | 		return fmt.Errorf("Must specify a PR index") | ||||||
|   | |||||||
| @@ -7,8 +7,8 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| 	"code.gitea.io/tea/modules/task" | 	"code.gitea.io/tea/modules/task" | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| @@ -41,7 +41,7 @@ var CmdPullsCreate = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error { | func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
|  |  | ||||||
| 	// no args -> interactive mode | 	// no args -> interactive mode | ||||||
| 	if ctx.NumFlags() == 0 { | 	if ctx.NumFlags() == 0 { | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| 	"code.gitea.io/tea/modules/utils" | 	"code.gitea.io/tea/modules/utils" | ||||||
| @@ -17,7 +18,7 @@ import ( | |||||||
|  |  | ||||||
| // editPullState abstracts the arg parsing to edit the given pull request | // editPullState abstracts the arg parsing to edit the given pull request | ||||||
| func editPullState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditPullRequestOption) error { | func editPullState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditPullRequestOption) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	if ctx.Args().Len() == 0 { | 	if ctx.Args().Len() == 0 { | ||||||
| 		return fmt.Errorf("Please provide a Pull Request index") | 		return fmt.Errorf("Please provide a Pull Request index") | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -30,7 +31,7 @@ var CmdPullsList = cli.Command{ | |||||||
|  |  | ||||||
| // RunPullsList return list of pulls | // RunPullsList return list of pulls | ||||||
| func RunPullsList(_ stdctx.Context, cmd *cli.Command) error { | func RunPullsList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	state := gitea.StateOpen | 	state := gitea.StateOpen | ||||||
| @@ -46,7 +47,6 @@ func RunPullsList(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| 	prs, _, err := ctx.Login.Client().ListRepoPullRequests(ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{ | 	prs, _, err := ctx.Login.Client().ListRepoPullRequests(ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{ | ||||||
| 		State: state, | 		State: state, | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| @@ -41,7 +42,7 @@ var CmdPullsMerge = cli.Command{ | |||||||
| 		}, | 		}, | ||||||
| 	}, flags.AllDefaultFlags...), | 	}, flags.AllDefaultFlags...), | ||||||
| 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 		ctx := context.InitCommand(cmd) | 		ctx := base.InitCommand(cmd) | ||||||
| 		ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 		ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 		if ctx.Args().Len() != 1 { | 		if ctx.Args().Len() != 1 { | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/task" | 	"code.gitea.io/tea/modules/task" | ||||||
| @@ -24,7 +25,7 @@ var CmdPullsReject = cli.Command{ | |||||||
| 	Description: "Request changes to a pull request", | 	Description: "Request changes to a pull request", | ||||||
| 	ArgsUsage:   "<pull index> <reason>", | 	ArgsUsage:   "<pull index> <reason>", | ||||||
| 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 		ctx := context.InitCommand(cmd) | 		ctx := base.InitCommand(cmd) | ||||||
| 		ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 		ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 		if ctx.Args().Len() < 2 { | 		if ctx.Args().Len() < 2 { | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/interact" | 	"code.gitea.io/tea/modules/interact" | ||||||
| @@ -22,7 +23,7 @@ var CmdPullsReview = cli.Command{ | |||||||
| 	Description: "Interactively review a pull request", | 	Description: "Interactively review a pull request", | ||||||
| 	ArgsUsage:   "<pull index>", | 	ArgsUsage:   "<pull index>", | ||||||
| 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 		ctx := context.InitCommand(cmd) | 		ctx := base.InitCommand(cmd) | ||||||
| 		ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 		ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 		if ctx.Args().Len() != 1 { | 		if ctx.Args().Len() != 1 { | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
|  |  | ||||||
| @@ -68,7 +69,7 @@ var CmdReleaseCreate = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runReleaseCreate(_ stdctx.Context, cmd *cli.Command) error { | func runReleaseCreate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	tag := ctx.String("tag") | 	tag := ctx.String("tag") | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
|  |  | ||||||
| @@ -35,7 +36,7 @@ var CmdReleaseDelete = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runReleaseDelete(_ stdctx.Context, cmd *cli.Command) error { | func runReleaseDelete(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| @@ -58,7 +59,7 @@ var CmdReleaseEdit = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runReleaseEdit(_ stdctx.Context, cmd *cli.Command) error { | func runReleaseEdit(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -31,7 +32,7 @@ var CmdReleaseList = cli.Command{ | |||||||
|  |  | ||||||
| // RunReleasesList list releases | // RunReleasesList list releases | ||||||
| func RunReleasesList(_ stdctx.Context, cmd *cli.Command) error { | func RunReleasesList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	releases, _, err := ctx.Login.Client().ListReleases(ctx.Owner, ctx.Repo, gitea.ListReleasesOptions{ | 	releases, _, err := ctx.Login.Client().ListReleases(ctx.Owner, ctx.Repo, gitea.ListReleasesOptions{ | ||||||
|   | |||||||
| @@ -6,8 +6,8 @@ package cmd | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/repos" | 	"code.gitea.io/tea/cmd/repos" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| 	"code.gitea.io/tea/modules/utils" | 	"code.gitea.io/tea/modules/utils" | ||||||
|  |  | ||||||
| @@ -44,7 +44,7 @@ func runRepos(ctx stdctx.Context, cmd *cli.Command) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func runRepoDetail(_ stdctx.Context, cmd *cli.Command, path string) error { | func runRepoDetail(_ stdctx.Context, cmd *cli.Command, path string) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
| 	repoOwner, repoName := utils.GetOwnerAndRepo(path, ctx.Owner) | 	repoOwner, repoName := utils.GetOwnerAndRepo(path, ctx.Owner) | ||||||
| 	repo, _, err := client.GetRepo(repoOwner, repoName) | 	repo, _, err := client.GetRepo(repoOwner, repoName) | ||||||
|   | |||||||
| @@ -7,8 +7,8 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
| @@ -103,7 +103,7 @@ var CmdRepoCreate = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runRepoCreate(_ stdctx.Context, cmd *cli.Command) error { | func runRepoCreate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
| 	var ( | 	var ( | ||||||
| 		repo       *gitea.Repository | 		repo       *gitea.Repository | ||||||
|   | |||||||
| @@ -9,8 +9,8 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| 	"code.gitea.io/tea/modules/utils" | 	"code.gitea.io/tea/modules/utils" | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| @@ -83,7 +83,7 @@ var CmdRepoCreateFromTemplate = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runRepoCreateFromTemplate(_ stdctx.Context, cmd *cli.Command) error { | func runRepoCreateFromTemplate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
| 	templateOwner, templateRepo := utils.GetOwnerAndRepo(ctx.String("template"), ctx.Login.User) | 	templateOwner, templateRepo := utils.GetOwnerAndRepo(ctx.String("template"), ctx.Login.User) | ||||||
|   | |||||||
| @@ -7,8 +7,8 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
|  |  | ||||||
| 	"github.com/charmbracelet/huh" | 	"github.com/charmbracelet/huh" | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| @@ -46,7 +46,7 @@ var CmdRepoRm = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runRepoDelete(_ stdctx.Context, cmd *cli.Command) error { | func runRepoDelete(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
|  |  | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -33,7 +34,7 @@ var CmdRepoFork = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runRepoFork(_ stdctx.Context, cmd *cli.Command) error { | func runRepoFork(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,8 +6,8 @@ package repos | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
| @@ -50,7 +50,7 @@ var CmdReposList = cli.Command{ | |||||||
|  |  | ||||||
| // RunReposList list repositories | // RunReposList list repositories | ||||||
| func RunReposList(_ stdctx.Context, cmd *cli.Command) error { | func RunReposList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	teaCmd := context.InitCommand(cmd) | 	teaCmd := base.InitCommand(cmd) | ||||||
| 	client := teaCmd.Login.Client() | 	client := teaCmd.Login.Client() | ||||||
|  |  | ||||||
| 	typeFilter, err := getTypeFilter(cmd) | 	typeFilter, err := getTypeFilter(cmd) | ||||||
|   | |||||||
| @@ -9,8 +9,8 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| ) | ) | ||||||
| @@ -109,7 +109,7 @@ var CmdRepoMigrate = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runRepoMigrate(_ stdctx.Context, cmd *cli.Command) error { | func runRepoMigrate(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
| 	var ( | 	var ( | ||||||
| 		repo    *gitea.Repository | 		repo    *gitea.Repository | ||||||
| @@ -157,7 +157,6 @@ func runRepoMigrate(_ stdctx.Context, cmd *cli.Command) error { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	repo, _, err = client.MigrateRepo(opts) | 	repo, _, err = client.MigrateRepo(opts) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -8,8 +8,8 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" |  | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
|  |  | ||||||
| 	"code.gitea.io/sdk/gitea" | 	"code.gitea.io/sdk/gitea" | ||||||
| @@ -57,7 +57,7 @@ var CmdReposSearch = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runReposSearch(_ stdctx.Context, cmd *cli.Command) error { | func runReposSearch(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	teaCmd := context.InitCommand(cmd) | 	teaCmd := base.InitCommand(cmd) | ||||||
| 	client := teaCmd.Login.Client() | 	client := teaCmd.Login.Client() | ||||||
|  |  | ||||||
| 	var ownerID int64 | 	var ownerID int64 | ||||||
|   | |||||||
| @@ -9,6 +9,7 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/utils" | 	"code.gitea.io/tea/modules/utils" | ||||||
| @@ -32,7 +33,7 @@ var CmdTrackedTimesAdd = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runTrackedTimesAdd(_ stdctx.Context, cmd *cli.Command) error { | func runTrackedTimesAdd(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
|  |  | ||||||
| 	if ctx.Args().Len() < 2 { | 	if ctx.Args().Len() < 2 { | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"strconv" | 	"strconv" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/utils" | 	"code.gitea.io/tea/modules/utils" | ||||||
| @@ -26,7 +27,7 @@ var CmdTrackedTimesDelete = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runTrackedTimesDelete(_ stdctx.Context, cmd *cli.Command) error { | func runTrackedTimesDelete(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -9,6 +9,7 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| @@ -70,7 +71,7 @@ Depending on your permissions on the repository, only your own tracked times mig | |||||||
|  |  | ||||||
| // RunTimesList list repositories | // RunTimesList list repositories | ||||||
| func RunTimesList(_ stdctx.Context, cmd *cli.Command) error { | func RunTimesList(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import ( | |||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  |  | ||||||
|  | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/cmd/flags" | 	"code.gitea.io/tea/cmd/flags" | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/modules/context" | ||||||
| 	"code.gitea.io/tea/modules/utils" | 	"code.gitea.io/tea/modules/utils" | ||||||
| @@ -25,7 +26,7 @@ var CmdTrackedTimesReset = cli.Command{ | |||||||
| } | } | ||||||
|  |  | ||||||
| func runTrackedTimesReset(_ stdctx.Context, cmd *cli.Command) error { | func runTrackedTimesReset(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 	ctx := context.InitCommand(cmd) | 	ctx := base.InitCommand(cmd) | ||||||
| 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | 	ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) | ||||||
| 	client := ctx.Login.Client() | 	client := ctx.Login.Client() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ package cmd | |||||||
| import ( | import ( | ||||||
| 	stdctx "context" | 	stdctx "context" | ||||||
|  |  | ||||||
| 	"code.gitea.io/tea/modules/context" | 	"code.gitea.io/tea/cmd/base" | ||||||
| 	"code.gitea.io/tea/modules/print" | 	"code.gitea.io/tea/modules/print" | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| ) | ) | ||||||
| @@ -19,7 +19,7 @@ var CmdWhoami = cli.Command{ | |||||||
| 	Usage:       "Show current logged in user", | 	Usage:       "Show current logged in user", | ||||||
| 	ArgsUsage:   " ", // command does not accept arguments | 	ArgsUsage:   " ", // command does not accept arguments | ||||||
| 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | 	Action: func(_ stdctx.Context, cmd *cli.Command) error { | ||||||
| 		ctx := context.InitCommand(cmd) | 		ctx := base.InitCommand(cmd) | ||||||
| 		client := ctx.Login.Client() | 		client := ctx.Login.Client() | ||||||
| 		user, _, _ := client.GetMyUserInfo() | 		user, _, _ := client.GetMyUserInfo() | ||||||
| 		print.UserDetails(user) | 		print.UserDetails(user) | ||||||
|   | |||||||
| @@ -6,7 +6,6 @@ package context | |||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"log" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"path" | 	"path" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| @@ -16,15 +15,11 @@ import ( | |||||||
| 	"code.gitea.io/tea/modules/config" | 	"code.gitea.io/tea/modules/config" | ||||||
| 	"code.gitea.io/tea/modules/debug" | 	"code.gitea.io/tea/modules/debug" | ||||||
| 	"code.gitea.io/tea/modules/git" | 	"code.gitea.io/tea/modules/git" | ||||||
| 	"code.gitea.io/tea/modules/theme" |  | ||||||
| 	"code.gitea.io/tea/modules/utils" |  | ||||||
|  |  | ||||||
| 	"github.com/charmbracelet/huh" |  | ||||||
| 	gogit "github.com/go-git/go-git/v5" |  | ||||||
| 	"github.com/urfave/cli/v3" | 	"github.com/urfave/cli/v3" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| var errNotAGiteaRepo = errors.New("No Gitea login found. You might want to specify --repo (and --login) to work outside of a repository") | var ErrNotAGiteaRepo = errors.New("No Gitea login found. You might want to specify --repo (and --login) to work outside of a repository") | ||||||
|  |  | ||||||
| // TeaContext contains all context derived during command initialization and wraps cli.Context | // TeaContext contains all context derived during command initialization and wraps cli.Context | ||||||
| type TeaContext struct { | type TeaContext struct { | ||||||
| @@ -65,108 +60,8 @@ type CtxRequirement struct { | |||||||
| 	RemoteRepo bool | 	RemoteRepo bool | ||||||
| } | } | ||||||
|  |  | ||||||
| // InitCommand resolves the application context, and returns the active login, and if | // ContextFromLocalRepo discovers login & repo slug from the default branch remote of the given local repo | ||||||
| // available the repo slug. It does this by reading the config file for logins, parsing | func ContextFromLocalRepo(repoPath, remoteValue string) (*git.TeaRepo, *config.Login, string, error) { | ||||||
| // the remotes of the .git repo specified in repoFlag or $PWD, and using overrides from |  | ||||||
| // command flags. If a local git repo can't be found, repo slug values are unset. |  | ||||||
| func InitCommand(cmd *cli.Command) *TeaContext { |  | ||||||
| 	// these flags are used as overrides to the context detection via local git repo |  | ||||||
| 	repoFlag := cmd.String("repo") |  | ||||||
| 	loginFlag := cmd.String("login") |  | ||||||
| 	remoteFlag := cmd.String("remote") |  | ||||||
|  |  | ||||||
| 	var ( |  | ||||||
| 		c                  TeaContext |  | ||||||
| 		err                error |  | ||||||
| 		repoPath           string // empty means PWD |  | ||||||
| 		repoFlagPathExists bool |  | ||||||
| 	) |  | ||||||
|  |  | ||||||
| 	// check if repoFlag can be interpreted as path to local repo. |  | ||||||
| 	if len(repoFlag) != 0 { |  | ||||||
| 		if repoFlagPathExists, err = utils.DirExists(repoFlag); err != nil { |  | ||||||
| 			log.Fatal(err.Error()) |  | ||||||
| 		} |  | ||||||
| 		if repoFlagPathExists { |  | ||||||
| 			repoPath = repoFlag |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if len(remoteFlag) == 0 { |  | ||||||
| 		remoteFlag = config.GetPreferences().FlagDefaults.Remote |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if repoPath == "" { |  | ||||||
| 		if repoPath, err = os.Getwd(); err != nil { |  | ||||||
| 			log.Fatal(err.Error()) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// try to read local git repo & extract context: if repoFlag specifies a valid path, read repo in that dir, |  | ||||||
| 	// otherwise attempt PWD. if no repo is found, continue with default login |  | ||||||
| 	if c.LocalRepo, c.Login, c.RepoSlug, err = contextFromLocalRepo(repoPath, remoteFlag); err != nil { |  | ||||||
| 		if err == errNotAGiteaRepo || err == gogit.ErrRepositoryNotExists { |  | ||||||
| 			// we can deal with that, commands needing the optional values use ctx.Ensure() |  | ||||||
| 		} else { |  | ||||||
| 			log.Fatal(err.Error()) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if len(repoFlag) != 0 && !repoFlagPathExists { |  | ||||||
| 		// if repoFlag is not a valid path, use it to override repoSlug |  | ||||||
| 		c.RepoSlug = repoFlag |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// override config user with env variable |  | ||||||
| 	envLogin := GetLoginByEnvVar() |  | ||||||
| 	if envLogin != nil { |  | ||||||
| 		_, err := utils.ValidateAuthenticationMethod(envLogin.URL, envLogin.Token, "", "", false, "", "") |  | ||||||
| 		if err != nil { |  | ||||||
| 			log.Fatal(err.Error()) |  | ||||||
| 		} |  | ||||||
| 		c.Login = envLogin |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// override login from flag, or use default login if repo based detection failed |  | ||||||
| 	if len(loginFlag) != 0 { |  | ||||||
| 		c.Login = config.GetLoginByName(loginFlag) |  | ||||||
| 		if c.Login == nil { |  | ||||||
| 			log.Fatalf("Login name '%s' does not exist", loginFlag) |  | ||||||
| 		} |  | ||||||
| 	} else if c.Login == nil { |  | ||||||
| 		if c.Login, err = config.GetDefaultLogin(); err != nil { |  | ||||||
| 			if err.Error() == "No available login" { |  | ||||||
| 				// TODO: maybe we can directly start interact.CreateLogin() (only if |  | ||||||
| 				// we're sure we can interactively!), as gh cli does. |  | ||||||
| 				fmt.Println(`No gitea login configured. To start using tea, first run |  | ||||||
|   tea login add |  | ||||||
| and then run your command again.`) |  | ||||||
| 			} |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		fallback := false |  | ||||||
| 		if err := huh.NewConfirm(). |  | ||||||
| 			Title(fmt.Sprintf("NOTE: no gitea login detected, whether falling back to login '%s'?", c.Login.Name)). |  | ||||||
| 			Value(&fallback). |  | ||||||
| 			WithTheme(theme.GetTheme()). |  | ||||||
| 			Run(); err != nil { |  | ||||||
| 			log.Fatalf("Get confirm failed: %v", err) |  | ||||||
| 		} |  | ||||||
| 		if !fallback { |  | ||||||
| 			os.Exit(1) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// parse reposlug (owner falling back to login owner if reposlug contains only repo name) |  | ||||||
| 	c.Owner, c.Repo = utils.GetOwnerAndRepo(c.RepoSlug, c.Login.User) |  | ||||||
| 	c.Command = cmd |  | ||||||
| 	c.Output = cmd.String("output") |  | ||||||
| 	return &c |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // contextFromLocalRepo discovers login & repo slug from the default branch remote of the given local repo |  | ||||||
| func contextFromLocalRepo(repoPath, remoteValue string) (*git.TeaRepo, *config.Login, string, error) { |  | ||||||
| 	repo, err := git.RepoFromPath(repoPath) | 	repo, err := git.RepoFromPath(repoPath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, nil, "", err | 		return nil, nil, "", err | ||||||
| @@ -178,7 +73,7 @@ func contextFromLocalRepo(repoPath, remoteValue string) (*git.TeaRepo, *config.L | |||||||
| 	debug.Printf("Get git config %v of %s in repo %s", gitConfig, remoteValue, repoPath) | 	debug.Printf("Get git config %v of %s in repo %s", gitConfig, remoteValue, repoPath) | ||||||
|  |  | ||||||
| 	if len(gitConfig.Remotes) == 0 { | 	if len(gitConfig.Remotes) == 0 { | ||||||
| 		return repo, nil, "", errNotAGiteaRepo | 		return repo, nil, "", ErrNotAGiteaRepo | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// When no preferred value is given, choose a remote to find a | 	// When no preferred value is given, choose a remote to find a | ||||||
| @@ -229,7 +124,7 @@ func contextFromLocalRepo(repoPath, remoteValue string) (*git.TeaRepo, *config.L | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return repo, nil, "", errNotAGiteaRepo | 	return repo, nil, "", ErrNotAGiteaRepo | ||||||
| } | } | ||||||
|  |  | ||||||
| // MatchLogins matches the given remoteURL against the provided logins and returns | // MatchLogins matches the given remoteURL against the provided logins and returns | ||||||
| @@ -274,7 +169,7 @@ func MatchLogins(remoteURL string, logins []config.Login) (*config.Login, string | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return nil, "", errNotAGiteaRepo | 	return nil, "", ErrNotAGiteaRepo | ||||||
| } | } | ||||||
|  |  | ||||||
| // GetLoginByEnvVar returns a login based on environment variables, or nil if no login can be created | // GetLoginByEnvVar returns a login based on environment variables, or nil if no login can be created | ||||||
|   | |||||||
| @@ -306,3 +306,39 @@ var tokenScopeOpts = []string{ | |||||||
| 	string(gitea.AccessTokenScopeReadApplication), | 	string(gitea.AccessTokenScopeReadApplication), | ||||||
| 	string(gitea.AccessTokenScopeSudo), | 	string(gitea.AccessTokenScopeSudo), | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func LoginSelect() (*config.Login, error) { | ||||||
|  | 	logins, err := config.GetLogins() | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  | 	if len(logins) == 0 { | ||||||
|  | 		return nil, errors.New("no gitea login configured") | ||||||
|  | 	} | ||||||
|  | 	if len(logins) == 1 { | ||||||
|  | 		return &logins[0], nil | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	loginNames := make([]string, 0, len(logins)) | ||||||
|  | 	for _, l := range logins { | ||||||
|  | 		loginNames = append(loginNames, l.Name) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	defaultLogin, _ := config.GetDefaultLogin() | ||||||
|  | 	var defaultValue string | ||||||
|  | 	if defaultLogin != nil { | ||||||
|  | 		defaultValue = defaultLogin.Name | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	loginName, err := promptSelect("Select gitea login: ", loginNames, "", "", defaultValue) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	for _, l := range logins { | ||||||
|  | 		if l.Name == loginName { | ||||||
|  | 			return &l, nil | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return nil, fmt.Errorf("login name '%s' does not exist", loginName) | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Lunny Xiao
					Lunny Xiao