mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-01 09:28: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:
6
Makefile
6
Makefile
@ -22,7 +22,7 @@ TEA_VERSION_TAG ?= $(shell sed 's/+/_/' <<< $(TEA_VERSION))
|
||||
|
||||
TAGS ?=
|
||||
SDK ?= $(shell $(GO) list -f '{{.Version}}' -m code.gitea.io/sdk/gitea)
|
||||
LDFLAGS := -X "main.Version=$(TEA_VERSION)" -X "main.Tags=$(TAGS)" -X "main.SDK=$(SDK)" -s -w
|
||||
LDFLAGS := -X "code.gitea.io/tea/cmd.Version=$(TEA_VERSION)" -X "code.gitea.io/tea/cmd.Tags=$(TAGS)" -X "code.gitea.io/tea/cmd.SDK=$(SDK)" -s -w
|
||||
|
||||
# override to allow passing additional goflags via make CLI
|
||||
override GOFLAGS := $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)'
|
||||
@ -83,11 +83,11 @@ fmt-check:
|
||||
|
||||
.PHONY: docs
|
||||
docs:
|
||||
$(GO) run . docs --out docs/CLI.md
|
||||
$(GO) run docs/docs.go --out docs/CLI.md
|
||||
|
||||
.PHONY: docs-check
|
||||
docs-check:
|
||||
@DIFF=$$($(GO) run . docs | diff docs/CLI.md -); \
|
||||
@DIFF=$$($(GO) run docs/docs.go | diff docs/CLI.md -); \
|
||||
if [ -n "$$DIFF" ]; then \
|
||||
echo "Please run 'make docs' and commit the result:"; \
|
||||
echo "$$DIFF"; \
|
||||
|
20
cmd/admin.go
20
cmd/admin.go
@ -4,10 +4,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/admin/users"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdAdmin represents the namespace of admin commands.
|
||||
@ -17,10 +19,10 @@ var CmdAdmin = cli.Command{
|
||||
Usage: "Operations requiring admin access on the Gitea instance",
|
||||
Aliases: []string{"a"},
|
||||
Category: catMisc,
|
||||
Action: func(cmd *cli.Context) error {
|
||||
Action: func(_ stdctx.Context, cmd *cli.Command) error {
|
||||
return cli.ShowSubcommandHelp(cmd)
|
||||
},
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&cmdAdminUsers,
|
||||
},
|
||||
}
|
||||
@ -29,19 +31,19 @@ var cmdAdminUsers = cli.Command{
|
||||
Name: "users",
|
||||
Aliases: []string{"u"},
|
||||
Usage: "Manage registered users",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runAdminUserDetail(ctx, ctx.Args().First())
|
||||
Action: func(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
if cmd.Args().Len() == 1 {
|
||||
return runAdminUserDetail(ctx, cmd, cmd.Args().First())
|
||||
}
|
||||
return users.RunUserList(ctx)
|
||||
return users.RunUserList(ctx, cmd)
|
||||
},
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&users.CmdUserList,
|
||||
},
|
||||
Flags: users.CmdUserList.Flags,
|
||||
}
|
||||
|
||||
func runAdminUserDetail(cmd *cli.Context, u string) error {
|
||||
func runAdminUserDetail(_ stdctx.Context, cmd *cli.Command, u string) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
user, _, err := client.GetUserInfo(u)
|
||||
|
@ -4,12 +4,14 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var userFieldsFlag = flags.FieldsFlag(print.UserFields, []string{
|
||||
@ -31,7 +33,7 @@ var CmdUserList = cli.Command{
|
||||
}
|
||||
|
||||
// RunUserList list users
|
||||
func RunUserList(cmd *cli.Context) error {
|
||||
func RunUserList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
|
||||
fields, err := userFieldsFlag.GetValues(cmd)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"code.gitea.io/tea/cmd/attachments"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdReleaseAttachments represents a release attachment (file attachment)
|
||||
@ -19,7 +19,7 @@ var CmdReleaseAttachments = cli.Command{
|
||||
Description: "Manage release assets",
|
||||
ArgsUsage: " ", // command does not accept arguments
|
||||
Action: attachments.RunReleaseAttachmentList,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&attachments.CmdReleaseAttachmentList,
|
||||
&attachments.CmdReleaseAttachmentCreate,
|
||||
&attachments.CmdReleaseAttachmentDelete,
|
||||
|
@ -4,6 +4,7 @@
|
||||
package attachments
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdReleaseAttachmentCreate represents a sub command of Release Attachments to create a release attachment
|
||||
@ -25,7 +26,7 @@ var CmdReleaseAttachmentCreate = cli.Command{
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
func runReleaseAttachmentCreate(cmd *cli.Context) error {
|
||||
func runReleaseAttachmentCreate(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -4,13 +4,14 @@
|
||||
package attachments
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdReleaseAttachmentDelete represents a sub command of Release Attachments to delete a release attachment
|
||||
@ -30,7 +31,7 @@ var CmdReleaseAttachmentDelete = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleaseAttachmentDelete(cmd *cli.Context) error {
|
||||
func runReleaseAttachmentDelete(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -4,6 +4,7 @@
|
||||
package attachments
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdReleaseAttachmentList represents a sub command of release attachment to list release attachments
|
||||
@ -29,7 +30,7 @@ var CmdReleaseAttachmentList = cli.Command{
|
||||
}
|
||||
|
||||
// RunReleaseAttachmentList list release attachments
|
||||
func RunReleaseAttachmentList(cmd *cli.Context) error {
|
||||
func RunReleaseAttachmentList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -4,6 +4,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
"os/exec"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdAutocomplete manages autocompletion
|
||||
@ -31,9 +32,9 @@ var CmdAutocomplete = cli.Command{
|
||||
Action: runAutocompleteAdd,
|
||||
}
|
||||
|
||||
func runAutocompleteAdd(ctx *cli.Context) error {
|
||||
func runAutocompleteAdd(_ context.Context, cmd *cli.Command) error {
|
||||
var remoteFile, localFile, cmds string
|
||||
shell := ctx.Args().First()
|
||||
shell := cmd.Args().First()
|
||||
|
||||
switch shell {
|
||||
case "zsh":
|
||||
@ -55,10 +56,10 @@ func runAutocompleteAdd(ctx *cli.Context) error {
|
||||
// fish is different, in that urfave/cli provides a generator for the shell script needed.
|
||||
// this also means that the fish completion can become out of sync with the tea binary!
|
||||
// writing to this directory suffices, as fish reads files there on startup, no cmds needed.
|
||||
return writeFishAutoCompleteFile(ctx)
|
||||
return writeFishAutoCompleteFile(cmd)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("Must specify valid %s", ctx.Command.ArgsUsage)
|
||||
return fmt.Errorf("Must specify valid %s", cmd.ArgsUsage)
|
||||
}
|
||||
|
||||
localPath, err := xdg.ConfigFile("tea/" + localFile)
|
||||
@ -71,7 +72,7 @@ func runAutocompleteAdd(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if ctx.Bool("install") {
|
||||
if cmd.Bool("install") {
|
||||
fmt.Println("Installing in your shellrc")
|
||||
installer := exec.Command(shell, "-c", cmds)
|
||||
if shell == "powershell" {
|
||||
@ -109,14 +110,14 @@ func writeRemoteAutoCompleteFile(file, destPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func writeFishAutoCompleteFile(ctx *cli.Context) error {
|
||||
func writeFishAutoCompleteFile(cmd *cli.Command) error {
|
||||
// NOTE: to make sure this file is in sync with tea commands, we'd need to
|
||||
// - check if the file exists
|
||||
// - if it does, check if the tea version that wrote it is the currently running version
|
||||
// - if not, rewrite the file
|
||||
// on each application run
|
||||
// NOTE: this generates a completion that also suggests file names, which looks kinda messy..
|
||||
script, err := ctx.App.ToFishCompletion()
|
||||
script, err := cmd.ToFishCompletion()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -4,9 +4,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/tea/cmd/branches"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdBranches represents to login a gitea server.
|
||||
@ -18,7 +20,7 @@ var CmdBranches = cli.Command{
|
||||
Description: `Lists branches when called without argument. If a branch is provided, will show it in detail.`,
|
||||
ArgsUsage: "[<branch name>]",
|
||||
Action: runBranches,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&branches.CmdBranchesList,
|
||||
&branches.CmdBranchesProtect,
|
||||
&branches.CmdBranchesUnprotect,
|
||||
@ -31,6 +33,6 @@ var CmdBranches = cli.Command{
|
||||
}, branches.CmdBranchesList.Flags...),
|
||||
}
|
||||
|
||||
func runBranches(ctx *cli.Context) error {
|
||||
return branches.RunBranchesList(ctx)
|
||||
func runBranches(ctx context.Context, cmd *cli.Command) error {
|
||||
return branches.RunBranchesList(ctx, cmd)
|
||||
}
|
||||
|
@ -4,12 +4,14 @@
|
||||
package branches
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var branchFieldsFlag = flags.FieldsFlag(print.BranchFields, []string{
|
||||
@ -35,7 +37,7 @@ var CmdBranchesList = cli.Command{
|
||||
}
|
||||
|
||||
// RunBranchesList list branches
|
||||
func RunBranchesList(cmd *cli.Context) error {
|
||||
func RunBranchesList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,13 +4,14 @@
|
||||
package branches
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdBranchesProtectFlags Flags for command protect/unprotect
|
||||
@ -43,7 +44,7 @@ var CmdBranchesUnprotect = cli.Command{
|
||||
}
|
||||
|
||||
// RunBranchesProtect function to protect/unprotect a list of branches
|
||||
func RunBranchesProtect(cmd *cli.Context) error {
|
||||
func RunBranchesProtect(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
17
cmd/clone.go
17
cmd/clone.go
@ -4,6 +4,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
@ -14,7 +15,7 @@ import (
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdRepoClone represents a sub command of repos to create a local copy
|
||||
@ -45,18 +46,18 @@ When a host is specified in the repo-slug, it will override the login specified
|
||||
},
|
||||
}
|
||||
|
||||
func runRepoClone(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
func runRepoClone(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
teaCmd := context.InitCommand(cmd)
|
||||
|
||||
args := ctx.Args()
|
||||
args := teaCmd.Args()
|
||||
if args.Len() < 1 {
|
||||
return cli.ShowCommandHelp(cmd, "clone")
|
||||
return cli.ShowCommandHelp(ctx, cmd, "clone")
|
||||
}
|
||||
dir := args.Get(1)
|
||||
|
||||
var (
|
||||
login *config.Login = ctx.Login
|
||||
owner string = ctx.Login.User
|
||||
login *config.Login = teaCmd.Login
|
||||
owner string = teaCmd.Login.User
|
||||
repo string
|
||||
)
|
||||
|
||||
@ -81,7 +82,7 @@ func runRepoClone(cmd *cli.Context) error {
|
||||
owner,
|
||||
repo,
|
||||
interact.PromptPassword,
|
||||
ctx.Int("depth"),
|
||||
teaCmd.Int("depth"),
|
||||
)
|
||||
|
||||
return err
|
||||
|
133
cmd/cmd.go
Normal file
133
cmd/cmd.go
Normal file
@ -0,0 +1,133 @@
|
||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Tea is command line tool for Gitea.
|
||||
package cmd // import "code.gitea.io/tea"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// Version holds the current tea version
|
||||
var Version = "development"
|
||||
|
||||
// Tags holds the build tags used
|
||||
var Tags = ""
|
||||
|
||||
// SDK holds the sdk version from go.mod
|
||||
var SDK = ""
|
||||
|
||||
// App creates and returns a tea Command with all subcommands set
|
||||
// it was separated from main so docs can be generated for it
|
||||
func App() *cli.Command {
|
||||
// make parsing tea --version easier, by printing /just/ the version string
|
||||
cli.VersionPrinter = func(c *cli.Command) { fmt.Fprintln(c.Writer, c.Version) }
|
||||
|
||||
return &cli.Command{
|
||||
Name: "tea",
|
||||
Usage: "command line tool to interact with Gitea",
|
||||
Description: appDescription,
|
||||
CustomHelpTemplate: helpTemplate,
|
||||
Version: formatVersion(),
|
||||
Commands: []*cli.Command{
|
||||
&CmdLogin,
|
||||
&CmdLogout,
|
||||
&CmdAutocomplete,
|
||||
&CmdWhoami,
|
||||
|
||||
&CmdIssues,
|
||||
&CmdPulls,
|
||||
&CmdLabels,
|
||||
&CmdMilestones,
|
||||
&CmdReleases,
|
||||
&CmdTrackedTimes,
|
||||
&CmdOrgs,
|
||||
&CmdRepos,
|
||||
&CmdBranches,
|
||||
&CmdAddComment,
|
||||
|
||||
&CmdOpen,
|
||||
&CmdNotifications,
|
||||
&CmdRepoClone,
|
||||
|
||||
&CmdAdmin,
|
||||
},
|
||||
EnableShellCompletion: true,
|
||||
}
|
||||
}
|
||||
|
||||
func formatVersion() string {
|
||||
version := fmt.Sprintf("Version: %s\tgolang: %s",
|
||||
bold(Version),
|
||||
strings.ReplaceAll(runtime.Version(), "go", ""))
|
||||
|
||||
if len(Tags) != 0 {
|
||||
version += fmt.Sprintf("\tbuilt with: %s", strings.Replace(Tags, " ", ", ", -1))
|
||||
}
|
||||
|
||||
if len(SDK) != 0 {
|
||||
version += fmt.Sprintf("\tgo-sdk: %s", SDK)
|
||||
}
|
||||
|
||||
return version
|
||||
}
|
||||
|
||||
var appDescription = `tea is a productivity helper for Gitea. It can be used to manage most entities on
|
||||
one or multiple Gitea instances & provides local helpers like 'tea pr checkout'.
|
||||
|
||||
tea tries to make use of context provided by the repository in $PWD if available.
|
||||
tea works best in a upstream/fork workflow, when the local main branch tracks the
|
||||
upstream repo. tea assumes that local git state is published on the remote before
|
||||
doing operations with tea. Configuration is persisted in $XDG_CONFIG_HOME/tea.
|
||||
`
|
||||
|
||||
var helpTemplate = bold(`
|
||||
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}`) + `
|
||||
{{if .Version}}{{if not .HideVersion}}version {{.Version}}{{end}}{{end}}
|
||||
|
||||
USAGE
|
||||
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .Commands}} command [subcommand] [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}}
|
||||
|
||||
DESCRIPTION
|
||||
{{.Description | nindent 3 | trim}}{{end}}{{if .VisibleCommands}}
|
||||
|
||||
COMMANDS{{range .VisibleCategories}}{{if .Name}}
|
||||
{{.Name}}:{{range .VisibleCommands}}
|
||||
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
|
||||
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
|
||||
|
||||
OPTIONS
|
||||
{{range $index, $option := .VisibleFlags}}{{if $index}}
|
||||
{{end}}{{$option}}{{end}}{{end}}
|
||||
|
||||
EXAMPLES
|
||||
tea login add # add a login once to get started
|
||||
|
||||
tea pulls # list open pulls for the repo in $PWD
|
||||
tea pulls --repo $HOME/foo # list open pulls for the repo in $HOME/foo
|
||||
tea pulls --remote upstream # list open pulls for the repo pointed at by
|
||||
# your local "upstream" git remote
|
||||
# list open pulls for any gitea repo at the given login instance
|
||||
tea pulls --repo gitea/tea --login gitea.com
|
||||
|
||||
tea milestone issues 0.7.0 # view open issues for milestone '0.7.0'
|
||||
tea issue 189 # view contents of issue 189
|
||||
tea open 189 # open web ui for issue 189
|
||||
tea open milestones # open web ui for milestones
|
||||
|
||||
# send gitea desktop notifications every 5 minutes (bash + libnotify)
|
||||
while :; do tea notifications --mine -o simple | xargs -i notify-send {}; sleep 300; done
|
||||
|
||||
ABOUT
|
||||
Written & maintained by The Gitea Authors.
|
||||
If you find a bug or want to contribute, we'll welcome you at https://gitea.com/gitea/tea.
|
||||
More info about Gitea itself on https://about.gitea.com.
|
||||
`
|
||||
|
||||
func bold(t string) string {
|
||||
return fmt.Sprintf("\033[1m%s\033[0m", t)
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
@ -17,7 +18,7 @@ import (
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdAddComment is the main command to operate with notifications
|
||||
@ -32,7 +33,7 @@ var CmdAddComment = cli.Command{
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
func runAddComment(cmd *cli.Context) error {
|
||||
func runAddComment(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
@ -49,7 +50,7 @@ func runAddComment(cmd *cli.Context) error {
|
||||
body := strings.Join(ctx.Args().Tail(), " ")
|
||||
if interact.IsStdinPiped() {
|
||||
// custom solution until https://github.com/AlecAivazis/survey/issues/328 is fixed
|
||||
if bodyStdin, err := io.ReadAll(ctx.App.Reader); err != nil {
|
||||
if bodyStdin, err := io.ReadAll(ctx.Reader); err != nil {
|
||||
return err
|
||||
} else if len(bodyStdin) != 0 {
|
||||
body = strings.Join([]string{body, string(bodyStdin)}, "\n\n")
|
||||
|
55
cmd/docs.go
55
cmd/docs.go
@ -1,55 +0,0 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// CmdDocs generates markdown for tea
|
||||
var CmdDocs = cli.Command{
|
||||
Name: "docs",
|
||||
Hidden: true,
|
||||
Description: "Generate CLI docs",
|
||||
Action: runDocs,
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "out",
|
||||
Usage: "Path to output docs to, otherwise prints to stdout",
|
||||
Aliases: []string{"o"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func runDocs(ctx *cli.Context) error {
|
||||
md, err := ctx.App.ToMarkdown()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
outPath := ctx.String("out")
|
||||
if outPath == "" {
|
||||
fmt.Print(md)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(outPath), os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fi, err := os.Create(outPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fi.Close()
|
||||
if _, err := fi.WriteString(md); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CsvFlag is a wrapper around cli.StringFlag, with an added GetValues() method
|
||||
@ -38,8 +38,8 @@ func NewCsvFlag(name, usage string, aliases, availableValues, defaults []string)
|
||||
}
|
||||
|
||||
// GetValues returns the value of the flag, parsed as a commaseparated list
|
||||
func (f CsvFlag) GetValues(ctx *cli.Context) ([]string, error) {
|
||||
val := ctx.String(f.Name)
|
||||
func (f CsvFlag) GetValues(cmd *cli.Command) ([]string, error) {
|
||||
val := cmd.String(f.Name)
|
||||
selection := strings.Split(val, ",")
|
||||
if f.AvailableFields != nil && val != "" {
|
||||
for _, field := range selection {
|
||||
|
@ -4,7 +4,7 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// LoginFlag provides flag to specify tea login profile
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"code.gitea.io/tea/modules/task"
|
||||
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// StateFlag provides flag to specify issue/pr state, defaulting to "open"
|
||||
|
@ -4,6 +4,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/issues"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdIssues represents to login a gitea server.
|
||||
@ -24,7 +25,7 @@ var CmdIssues = cli.Command{
|
||||
Description: `Lists issues when called without argument. If issue index is provided, will show it in detail.`,
|
||||
ArgsUsage: "[<issue index>]",
|
||||
Action: runIssues,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&issues.CmdIssuesList,
|
||||
&issues.CmdIssuesCreate,
|
||||
&issues.CmdIssuesEdit,
|
||||
@ -39,14 +40,14 @@ var CmdIssues = cli.Command{
|
||||
}, issues.CmdIssuesList.Flags...),
|
||||
}
|
||||
|
||||
func runIssues(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runIssueDetail(ctx, ctx.Args().First())
|
||||
func runIssues(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
if cmd.Args().Len() == 1 {
|
||||
return runIssueDetail(ctx, cmd, cmd.Args().First())
|
||||
}
|
||||
return issues.RunIssuesList(ctx)
|
||||
return issues.RunIssuesList(ctx, cmd)
|
||||
}
|
||||
|
||||
func runIssueDetail(cmd *cli.Context, index string) error {
|
||||
func runIssueDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
package issues
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdIssuesClose represents a sub command of issues to close an issue
|
||||
@ -21,15 +22,15 @@ var CmdIssuesClose = cli.Command{
|
||||
Usage: "Change state of one ore more issues to 'closed'",
|
||||
Description: `Change state of one ore more issues to 'closed'`,
|
||||
ArgsUsage: "<issue index> [<issue index>...]",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
Action: func(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
var s = gitea.StateClosed
|
||||
return editIssueState(ctx, gitea.EditIssueOption{State: &s})
|
||||
return editIssueState(ctx, cmd, gitea.EditIssueOption{State: &s})
|
||||
},
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
// editIssueState abstracts the arg parsing to edit the given issue
|
||||
func editIssueState(cmd *cli.Context, opts gitea.EditIssueOption) error {
|
||||
func editIssueState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditIssueOption) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
if ctx.Args().Len() == 0 {
|
||||
|
@ -4,12 +4,14 @@
|
||||
package issues
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdIssuesCreate represents a sub command of issues to create issue
|
||||
@ -23,7 +25,7 @@ var CmdIssuesCreate = cli.Command{
|
||||
Flags: flags.IssuePRCreateFlags,
|
||||
}
|
||||
|
||||
func runIssuesCreate(cmd *cli.Context) error {
|
||||
func runIssuesCreate(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -6,14 +6,15 @@ package issues
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdIssuesEdit is the subcommand of issues to edit issues
|
||||
@ -28,7 +29,7 @@ use an empty string (eg. --milestone "").`,
|
||||
Flags: flags.IssuePREditFlags,
|
||||
}
|
||||
|
||||
func runIssuesEdit(cmd *cli.Context) error {
|
||||
func runIssuesEdit(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
package issues
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@ -13,7 +14,7 @@ import (
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var issueFieldsFlag = flags.FieldsFlag(print.IssueFields, []string{
|
||||
@ -32,7 +33,7 @@ var CmdIssuesList = cli.Command{
|
||||
}
|
||||
|
||||
// RunIssuesList list issues
|
||||
func RunIssuesList(cmd *cli.Context) error {
|
||||
func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
|
||||
state := gitea.StateOpen
|
||||
|
@ -4,10 +4,12 @@
|
||||
package issues
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdIssuesReopen represents a sub command of issues to open an issue
|
||||
@ -17,9 +19,9 @@ var CmdIssuesReopen = cli.Command{
|
||||
Usage: "Change state of one or more issues to 'open'",
|
||||
Description: `Change state of one or more issues to 'open'`,
|
||||
ArgsUsage: "<issue index> [<issue index>...]",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
var s = gitea.StateOpen
|
||||
return editIssueState(ctx, gitea.EditIssueOption{State: &s})
|
||||
return editIssueState(ctx, cmd, gitea.EditIssueOption{State: &s})
|
||||
},
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
@ -4,10 +4,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/labels"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLabels represents to operate repositories' labels.
|
||||
@ -19,7 +20,7 @@ var CmdLabels = cli.Command{
|
||||
Description: `Manage issue labels`,
|
||||
ArgsUsage: " ", // command does not accept arguments
|
||||
Action: runLabels,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&labels.CmdLabelsList,
|
||||
&labels.CmdLabelCreate,
|
||||
&labels.CmdLabelUpdate,
|
||||
@ -28,13 +29,13 @@ var CmdLabels = cli.Command{
|
||||
Flags: labels.CmdLabelsList.Flags,
|
||||
}
|
||||
|
||||
func runLabels(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runLabelsDetails(ctx)
|
||||
func runLabels(ctx context.Context, cmd *cli.Command) error {
|
||||
if cmd.Args().Len() == 1 {
|
||||
return runLabelsDetails(cmd)
|
||||
}
|
||||
return labels.RunLabelsList(ctx)
|
||||
return labels.RunLabelsList(ctx, cmd)
|
||||
}
|
||||
|
||||
func runLabelsDetails(ctx *cli.Context) error {
|
||||
func runLabelsDetails(cmd *cli.Command) error {
|
||||
return fmt.Errorf("Not yet implemented")
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ package labels
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
stdctx "context"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
@ -13,7 +14,7 @@ import (
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLabelCreate represents a sub command of labels to create label.
|
||||
@ -44,7 +45,7 @@ var CmdLabelCreate = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runLabelCreate(cmd *cli.Context) error {
|
||||
func runLabelCreate(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,10 +4,12 @@
|
||||
package labels
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLabelDelete represents a sub command of labels to delete label.
|
||||
@ -26,7 +28,7 @@ var CmdLabelDelete = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runLabelDelete(cmd *cli.Context) error {
|
||||
func runLabelDelete(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,13 +4,15 @@
|
||||
package labels
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLabelsList represents a sub command of labels to list labels
|
||||
@ -33,7 +35,7 @@ var CmdLabelsList = cli.Command{
|
||||
}
|
||||
|
||||
// RunLabelsList list labels.
|
||||
func RunLabelsList(cmd *cli.Context) error {
|
||||
func RunLabelsList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,11 +4,13 @@
|
||||
package labels
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLabelUpdate represents a sub command of labels to update label.
|
||||
@ -38,7 +40,7 @@ var CmdLabelUpdate = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runLabelUpdate(cmd *cli.Context) error {
|
||||
func runLabelUpdate(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
13
cmd/login.go
13
cmd/login.go
@ -4,13 +4,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/login"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLogin represents to login a gitea server.
|
||||
@ -22,7 +23,7 @@ var CmdLogin = cli.Command{
|
||||
Description: `Log in to a Gitea server`,
|
||||
ArgsUsage: "[<login name>]",
|
||||
Action: runLogins,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&login.CmdLoginList,
|
||||
&login.CmdLoginAdd,
|
||||
&login.CmdLoginEdit,
|
||||
@ -33,11 +34,11 @@ var CmdLogin = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func runLogins(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runLoginDetail(ctx.Args().First())
|
||||
func runLogins(ctx context.Context, cmd *cli.Command) error {
|
||||
if cmd.Args().Len() == 1 {
|
||||
return runLoginDetail(cmd.Args().First())
|
||||
}
|
||||
return login.RunLoginList(ctx)
|
||||
return login.RunLoginList(ctx, cmd)
|
||||
}
|
||||
|
||||
func runLoginDetail(name string) error {
|
||||
|
@ -4,11 +4,13 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/tea/modules/auth"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLoginAdd represents to login a gitea server.
|
||||
@ -27,7 +29,7 @@ var CmdLoginAdd = cli.Command{
|
||||
Name: "url",
|
||||
Aliases: []string{"u"},
|
||||
Value: "https://gitea.com",
|
||||
EnvVars: []string{"GITEA_SERVER_URL"},
|
||||
Sources: cli.EnvVars("GITEA_SERVER_URL"),
|
||||
Usage: "Server URL",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
@ -39,30 +41,30 @@ var CmdLoginAdd = cli.Command{
|
||||
Name: "token",
|
||||
Aliases: []string{"t"},
|
||||
Value: "",
|
||||
EnvVars: []string{"GITEA_SERVER_TOKEN"},
|
||||
Sources: cli.EnvVars("GITEA_SERVER_TOKEN"),
|
||||
Usage: "Access token. Can be obtained from Settings > Applications",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "user",
|
||||
Value: "",
|
||||
EnvVars: []string{"GITEA_SERVER_USER"},
|
||||
Sources: cli.EnvVars("GITEA_SERVER_USER"),
|
||||
Usage: "User for basic auth (will create token)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "password",
|
||||
Aliases: []string{"pwd"},
|
||||
Value: "",
|
||||
EnvVars: []string{"GITEA_SERVER_PASSWORD"},
|
||||
Sources: cli.EnvVars("GITEA_SERVER_PASSWORD"),
|
||||
Usage: "Password for basic auth (will create token)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "otp",
|
||||
EnvVars: []string{"GITEA_SERVER_OTP"},
|
||||
Sources: cli.EnvVars("GITEA_SERVER_OTP"),
|
||||
Usage: "OTP token for auth, if necessary",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "scopes",
|
||||
EnvVars: []string{"GITEA_SCOPES"},
|
||||
Sources: cli.EnvVars("GITEA_SCOPES"),
|
||||
Usage: "Token scopes to add when creating a new token, separated by a comma",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
@ -107,53 +109,53 @@ var CmdLoginAdd = cli.Command{
|
||||
Action: runLoginAdd,
|
||||
}
|
||||
|
||||
func runLoginAdd(ctx *cli.Context) error {
|
||||
func runLoginAdd(_ context.Context, cmd *cli.Command) error {
|
||||
// if no args create login interactive
|
||||
if ctx.NumFlags() == 0 {
|
||||
if cmd.NumFlags() == 0 {
|
||||
return interact.CreateLogin()
|
||||
}
|
||||
|
||||
// if OAuth flag is provided, use OAuth2 PKCE flow
|
||||
if ctx.Bool("oauth") {
|
||||
if cmd.Bool("oauth") {
|
||||
opts := auth.OAuthOptions{
|
||||
Name: ctx.String("name"),
|
||||
URL: ctx.String("url"),
|
||||
Insecure: ctx.Bool("insecure"),
|
||||
Name: cmd.String("name"),
|
||||
URL: cmd.String("url"),
|
||||
Insecure: cmd.Bool("insecure"),
|
||||
}
|
||||
|
||||
// Only set clientID if provided
|
||||
if ctx.String("client-id") != "" {
|
||||
opts.ClientID = ctx.String("client-id")
|
||||
if cmd.String("client-id") != "" {
|
||||
opts.ClientID = cmd.String("client-id")
|
||||
}
|
||||
|
||||
// Only set redirect URL if provided
|
||||
if ctx.String("redirect-url") != "" {
|
||||
opts.RedirectURL = ctx.String("redirect-url")
|
||||
if cmd.String("redirect-url") != "" {
|
||||
opts.RedirectURL = cmd.String("redirect-url")
|
||||
}
|
||||
|
||||
return auth.OAuthLoginWithFullOptions(opts)
|
||||
}
|
||||
|
||||
sshAgent := false
|
||||
if ctx.String("ssh-agent-key") != "" || ctx.String("ssh-agent-principal") != "" {
|
||||
if cmd.String("ssh-agent-key") != "" || cmd.String("ssh-agent-principal") != "" {
|
||||
sshAgent = true
|
||||
}
|
||||
|
||||
// else use args to add login
|
||||
return task.CreateLogin(
|
||||
ctx.String("name"),
|
||||
ctx.String("token"),
|
||||
ctx.String("user"),
|
||||
ctx.String("password"),
|
||||
ctx.String("otp"),
|
||||
ctx.String("scopes"),
|
||||
ctx.String("ssh-key"),
|
||||
ctx.String("url"),
|
||||
ctx.String("ssh-agent-principal"),
|
||||
ctx.String("ssh-agent-key"),
|
||||
ctx.Bool("insecure"),
|
||||
cmd.String("name"),
|
||||
cmd.String("token"),
|
||||
cmd.String("user"),
|
||||
cmd.String("password"),
|
||||
cmd.String("otp"),
|
||||
cmd.String("scopes"),
|
||||
cmd.String("ssh-key"),
|
||||
cmd.String("url"),
|
||||
cmd.String("ssh-agent-principal"),
|
||||
cmd.String("ssh-agent-key"),
|
||||
cmd.Bool("insecure"),
|
||||
sshAgent,
|
||||
!ctx.Bool("no-version-check"),
|
||||
ctx.Bool("helper"),
|
||||
!cmd.Bool("no-version-check"),
|
||||
cmd.Bool("helper"),
|
||||
)
|
||||
}
|
||||
|
@ -4,12 +4,13 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLoginSetDefault represents to login a gitea server.
|
||||
@ -22,8 +23,8 @@ var CmdLoginSetDefault = cli.Command{
|
||||
Flags: []cli.Flag{&flags.OutputFlag},
|
||||
}
|
||||
|
||||
func runLoginSetDefault(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 0 {
|
||||
func runLoginSetDefault(_ context.Context, cmd *cli.Command) error {
|
||||
if cmd.Args().Len() == 0 {
|
||||
l, err := config.GetDefaultLogin()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -32,6 +33,6 @@ func runLoginSetDefault(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
name := ctx.Args().First()
|
||||
name := cmd.Args().First()
|
||||
return config.SetDefaultLogin(name)
|
||||
}
|
||||
|
@ -4,12 +4,13 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/modules/config"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLoginDelete is a command to delete a login
|
||||
@ -23,7 +24,7 @@ var CmdLoginDelete = cli.Command{
|
||||
}
|
||||
|
||||
// RunLoginDelete runs the action of a login delete command
|
||||
func RunLoginDelete(ctx *cli.Context) error {
|
||||
func RunLoginDelete(_ context.Context, cmd *cli.Command) error {
|
||||
logins, err := config.GetLogins()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -31,8 +32,8 @@ func RunLoginDelete(ctx *cli.Context) error {
|
||||
|
||||
var name string
|
||||
|
||||
if len(ctx.Args().First()) != 0 {
|
||||
name = ctx.Args().First()
|
||||
if len(cmd.Args().First()) != 0 {
|
||||
name = cmd.Args().First()
|
||||
} else if len(logins) == 1 {
|
||||
name = logins[0].Name
|
||||
} else {
|
||||
|
@ -4,6 +4,7 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
"code.gitea.io/tea/modules/config"
|
||||
|
||||
"github.com/skratchdot/open-golang/open"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLoginEdit represents to login a gitea server.
|
||||
@ -26,7 +27,7 @@ var CmdLoginEdit = cli.Command{
|
||||
Flags: []cli.Flag{&flags.OutputFlag},
|
||||
}
|
||||
|
||||
func runLoginEdit(_ *cli.Context) error {
|
||||
func runLoginEdit(_ context.Context, _ *cli.Command) error {
|
||||
if e, ok := os.LookupEnv("EDITOR"); ok && e != "" {
|
||||
cmd := exec.Command(e, config.GetConfigPath())
|
||||
cmd.Stdin = os.Stdin
|
||||
|
@ -5,6 +5,7 @@ package login
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
@ -15,7 +16,7 @@ import (
|
||||
"code.gitea.io/tea/modules/auth"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLoginHelper represents to login a gitea helper.
|
||||
@ -25,19 +26,19 @@ var CmdLoginHelper = cli.Command{
|
||||
Usage: "Git helper",
|
||||
Description: `Git helper`,
|
||||
Hidden: true,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "store",
|
||||
Description: "Command drops",
|
||||
Aliases: []string{"erase"},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
Action: func(_ context.Context, _ *cli.Command) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "setup",
|
||||
Description: "Setup helper to tea authenticate",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
Action: func(_ context.Context, _ *cli.Command) error {
|
||||
logins, err := config.GetLogins()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -58,7 +59,7 @@ var CmdLoginHelper = cli.Command{
|
||||
{
|
||||
Name: "get",
|
||||
Description: "Get token to auth",
|
||||
Action: func(cmd *cli.Context) error {
|
||||
Action: func(_ context.Context, cmd *cli.Command) error {
|
||||
wants := map[string]string{}
|
||||
s := bufio.NewScanner(os.Stdin)
|
||||
for s.Scan() {
|
||||
|
@ -4,11 +4,13 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLoginList represents to login a gitea server.
|
||||
@ -23,7 +25,7 @@ var CmdLoginList = cli.Command{
|
||||
}
|
||||
|
||||
// RunLoginList list all logins
|
||||
func RunLoginList(cmd *cli.Context) error {
|
||||
func RunLoginList(_ context.Context, cmd *cli.Command) error {
|
||||
logins, err := config.GetLogins()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -4,12 +4,13 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/modules/auth"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLoginOAuthRefresh represents a command to refresh an OAuth token
|
||||
@ -21,12 +22,12 @@ var CmdLoginOAuthRefresh = cli.Command{
|
||||
Action: runLoginOAuthRefresh,
|
||||
}
|
||||
|
||||
func runLoginOAuthRefresh(ctx *cli.Context) error {
|
||||
func runLoginOAuthRefresh(_ context.Context, cmd *cli.Command) error {
|
||||
var loginName string
|
||||
|
||||
// Get login name from args or use default
|
||||
if ctx.Args().Len() > 0 {
|
||||
loginName = ctx.Args().First()
|
||||
if cmd.Args().Len() > 0 {
|
||||
loginName = cmd.Args().First()
|
||||
} else {
|
||||
// Get default login
|
||||
login, err := config.GetDefaultLogin()
|
||||
|
@ -6,7 +6,7 @@ package cmd
|
||||
import (
|
||||
"code.gitea.io/tea/cmd/login"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdLogout represents to logout a gitea server.
|
||||
|
@ -4,11 +4,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/milestones"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdMilestones represents to operate repositories milestones.
|
||||
@ -20,7 +21,7 @@ var CmdMilestones = cli.Command{
|
||||
Description: `List and create milestones`,
|
||||
ArgsUsage: "[<milestone name>]",
|
||||
Action: runMilestones,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&milestones.CmdMilestonesList,
|
||||
&milestones.CmdMilestonesCreate,
|
||||
&milestones.CmdMilestonesClose,
|
||||
@ -31,14 +32,14 @@ var CmdMilestones = cli.Command{
|
||||
Flags: milestones.CmdMilestonesList.Flags,
|
||||
}
|
||||
|
||||
func runMilestones(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runMilestoneDetail(ctx, ctx.Args().First())
|
||||
func runMilestones(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
if cmd.Args().Len() == 1 {
|
||||
return runMilestoneDetail(ctx, cmd, cmd.Args().First())
|
||||
}
|
||||
return milestones.RunMilestonesList(ctx)
|
||||
return milestones.RunMilestonesList(ctx, cmd)
|
||||
}
|
||||
|
||||
func runMilestoneDetail(cmd *cli.Context, name string) error {
|
||||
func runMilestoneDetail(_ stdctx.Context, cmd *cli.Command, name string) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -4,9 +4,10 @@
|
||||
package milestones
|
||||
|
||||
import (
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdMilestonesClose represents a sub command of milestones to close an milestone
|
||||
@ -15,11 +16,11 @@ var CmdMilestonesClose = cli.Command{
|
||||
Usage: "Change state of one or more milestones to 'closed'",
|
||||
Description: `Change state of one or more milestones to 'closed'`,
|
||||
ArgsUsage: "<milestone name> [<milestone name>...]",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
if ctx.Bool("force") {
|
||||
return deleteMilestone(ctx)
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
if cmd.Bool("force") {
|
||||
return deleteMilestone(ctx, cmd)
|
||||
}
|
||||
return editMilestoneStatus(ctx, true)
|
||||
return editMilestoneStatus(ctx, cmd, true)
|
||||
},
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
|
@ -6,14 +6,15 @@ package milestones
|
||||
import (
|
||||
"time"
|
||||
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdMilestonesCreate represents a sub command of milestones to create milestone
|
||||
@ -48,7 +49,7 @@ var CmdMilestonesCreate = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runMilestonesCreate(cmd *cli.Context) error {
|
||||
func runMilestonesCreate(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
|
||||
date := ctx.String("deadline")
|
||||
|
@ -4,10 +4,12 @@
|
||||
package milestones
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdMilestonesDelete represents a sub command of milestones to delete an milestone
|
||||
@ -21,7 +23,7 @@ var CmdMilestonesDelete = cli.Command{
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
func deleteMilestone(cmd *cli.Context) error {
|
||||
func deleteMilestone(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -6,13 +6,14 @@ package milestones
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var msIssuesFieldsFlag = flags.FieldsFlag(print.IssueFields, []string{
|
||||
@ -27,7 +28,7 @@ var CmdMilestonesIssues = cli.Command{
|
||||
Description: "manage issue/pull of an milestone",
|
||||
ArgsUsage: "<milestone name>",
|
||||
Action: runMilestoneIssueList,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&CmdMilestoneAddIssue,
|
||||
&CmdMilestoneRemoveIssue,
|
||||
},
|
||||
@ -69,7 +70,7 @@ var CmdMilestoneRemoveIssue = cli.Command{
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
func runMilestoneIssueList(cmd *cli.Context) error {
|
||||
func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
@ -119,7 +120,7 @@ func runMilestoneIssueList(cmd *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func runMilestoneIssueAdd(cmd *cli.Context) error {
|
||||
func runMilestoneIssueAdd(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
@ -146,7 +147,7 @@ func runMilestoneIssueAdd(cmd *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func runMilestoneIssueRemove(cmd *cli.Context) error {
|
||||
func runMilestoneIssueRemove(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -4,12 +4,14 @@
|
||||
package milestones
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var fieldsFlag = flags.FieldsFlag(print.MilestoneFields, []string{
|
||||
@ -37,7 +39,7 @@ var CmdMilestonesList = cli.Command{
|
||||
}
|
||||
|
||||
// RunMilestonesList list milestones
|
||||
func RunMilestonesList(cmd *cli.Context) error {
|
||||
func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
package milestones
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdMilestonesReopen represents a sub command of milestones to open an milestone
|
||||
@ -21,13 +22,13 @@ var CmdMilestonesReopen = cli.Command{
|
||||
Usage: "Change state of one or more milestones to 'open'",
|
||||
Description: `Change state of one or more milestones to 'open'`,
|
||||
ArgsUsage: "<milestone name> [<milestone name> ...]",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
return editMilestoneStatus(ctx, false)
|
||||
Action: func(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
return editMilestoneStatus(ctx, cmd, false)
|
||||
},
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
func editMilestoneStatus(cmd *cli.Context, close bool) error {
|
||||
func editMilestoneStatus(_ stdctx.Context, cmd *cli.Command, close bool) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
if ctx.Args().Len() == 0 {
|
||||
|
@ -6,7 +6,7 @@ package cmd
|
||||
import (
|
||||
"code.gitea.io/tea/cmd/notifications"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdNotifications is the main command to operate with notifications
|
||||
@ -17,7 +17,7 @@ var CmdNotifications = cli.Command{
|
||||
Usage: "Show notifications",
|
||||
Description: "Show notifications, by default based on the current repo if available",
|
||||
Action: notifications.RunNotificationsList,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
¬ifications.CmdNotificationsList,
|
||||
¬ifications.CmdNotificationsMarkRead,
|
||||
¬ifications.CmdNotificationsMarkUnread,
|
||||
|
@ -4,6 +4,7 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var notifyFieldsFlag = flags.FieldsFlag(print.NotificationFields, []string{
|
||||
@ -36,9 +37,9 @@ var CmdNotificationsList = cli.Command{
|
||||
}
|
||||
|
||||
// RunNotificationsList list notifications
|
||||
func RunNotificationsList(ctx *cli.Context) error {
|
||||
func RunNotificationsList(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
var states []gitea.NotifyStatus
|
||||
statesStr, err := flags.NotificationStateFlag.GetValues(ctx)
|
||||
statesStr, err := flags.NotificationStateFlag.GetValues(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -47,7 +48,7 @@ func RunNotificationsList(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
var types []gitea.NotifySubjectType
|
||||
typesStr, err := notifyTypeFlag.GetValues(ctx)
|
||||
typesStr, err := notifyTypeFlag.GetValues(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -55,11 +56,11 @@ func RunNotificationsList(ctx *cli.Context) error {
|
||||
types = append(types, gitea.NotifySubjectType(t))
|
||||
}
|
||||
|
||||
return listNotifications(ctx, states, types)
|
||||
return listNotifications(ctx, cmd, states, types)
|
||||
}
|
||||
|
||||
// listNotifications will get the notifications based on status and subject type
|
||||
func listNotifications(cmd *cli.Context, status []gitea.NotifyStatus, subjects []gitea.NotifySubjectType) error {
|
||||
func listNotifications(_ stdctx.Context, cmd *cli.Command, status []gitea.NotifyStatus, subjects []gitea.NotifySubjectType) error {
|
||||
var news []*gitea.NotificationThread
|
||||
var err error
|
||||
|
||||
|
@ -4,13 +4,14 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdNotificationsMarkRead represents a sub command of notifications to list read notifications
|
||||
@ -21,16 +22,16 @@ var CmdNotificationsMarkRead = cli.Command{
|
||||
Description: "Mark all filtered or a specific notification as read",
|
||||
ArgsUsage: "[all | <notification id>]",
|
||||
Flags: flags.NotificationFlags,
|
||||
Action: func(ctx *cli.Context) error {
|
||||
cmd := context.InitCommand(ctx)
|
||||
filter, err := flags.NotificationStateFlag.GetValues(ctx)
|
||||
Action: func(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
filter, err := flags.NotificationStateFlag.GetValues(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !cmd.IsSet(flags.NotificationStateFlag.Name) {
|
||||
if !ctx.IsSet(flags.NotificationStateFlag.Name) {
|
||||
filter = []string{string(gitea.NotifyStatusUnread)}
|
||||
}
|
||||
return markNotificationAs(cmd, filter, gitea.NotifyStatusRead)
|
||||
return markNotificationAs(ctx, filter, gitea.NotifyStatusRead)
|
||||
},
|
||||
}
|
||||
|
||||
@ -42,16 +43,16 @@ var CmdNotificationsMarkUnread = cli.Command{
|
||||
Description: "Mark all filtered or a specific notification as unread",
|
||||
ArgsUsage: "[all | <notification id>]",
|
||||
Flags: flags.NotificationFlags,
|
||||
Action: func(ctx *cli.Context) error {
|
||||
cmd := context.InitCommand(ctx)
|
||||
filter, err := flags.NotificationStateFlag.GetValues(ctx)
|
||||
Action: func(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
filter, err := flags.NotificationStateFlag.GetValues(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !cmd.IsSet(flags.NotificationStateFlag.Name) {
|
||||
if !ctx.IsSet(flags.NotificationStateFlag.Name) {
|
||||
filter = []string{string(gitea.NotifyStatusRead)}
|
||||
}
|
||||
return markNotificationAs(cmd, filter, gitea.NotifyStatusUnread)
|
||||
return markNotificationAs(ctx, filter, gitea.NotifyStatusUnread)
|
||||
},
|
||||
}
|
||||
|
||||
@ -63,16 +64,16 @@ var CmdNotificationsMarkPinned = cli.Command{
|
||||
Description: "Mark all filtered or a specific notification as pinned",
|
||||
ArgsUsage: "[all | <notification id>]",
|
||||
Flags: flags.NotificationFlags,
|
||||
Action: func(ctx *cli.Context) error {
|
||||
cmd := context.InitCommand(ctx)
|
||||
filter, err := flags.NotificationStateFlag.GetValues(ctx)
|
||||
Action: func(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
filter, err := flags.NotificationStateFlag.GetValues(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !cmd.IsSet(flags.NotificationStateFlag.Name) {
|
||||
if !ctx.IsSet(flags.NotificationStateFlag.Name) {
|
||||
filter = []string{string(gitea.NotifyStatusUnread)}
|
||||
}
|
||||
return markNotificationAs(cmd, filter, gitea.NotifyStatusPinned)
|
||||
return markNotificationAs(ctx, filter, gitea.NotifyStatusPinned)
|
||||
},
|
||||
}
|
||||
|
||||
@ -83,11 +84,11 @@ var CmdNotificationsUnpin = cli.Command{
|
||||
Description: "Marks all pinned or a specific notification as read",
|
||||
ArgsUsage: "[all | <notification id>]",
|
||||
Flags: flags.NotificationFlags,
|
||||
Action: func(ctx *cli.Context) error {
|
||||
cmd := context.InitCommand(ctx)
|
||||
Action: func(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
filter := []string{string(gitea.NotifyStatusPinned)}
|
||||
// NOTE: we implicitly mark it as read, to match web UI semantics. marking as unread might be more useful?
|
||||
return markNotificationAs(cmd, filter, gitea.NotifyStatusRead)
|
||||
return markNotificationAs(ctx, filter, gitea.NotifyStatusRead)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
@ -12,7 +13,7 @@ import (
|
||||
local_git "code.gitea.io/tea/modules/git"
|
||||
|
||||
"github.com/skratchdot/open-golang/open"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdOpen represents a sub command of issues to open issue on the web browser
|
||||
@ -26,7 +27,7 @@ var CmdOpen = cli.Command{
|
||||
Flags: append([]cli.Flag{}, flags.LoginRepoFlags...),
|
||||
}
|
||||
|
||||
func runOpen(cmd *cli.Context) error {
|
||||
func runOpen(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,11 +4,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/organizations"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdOrgs represents handle organization
|
||||
@ -20,7 +22,7 @@ var CmdOrgs = cli.Command{
|
||||
Description: "Show organization details",
|
||||
ArgsUsage: "[<organization>]",
|
||||
Action: runOrganizations,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&organizations.CmdOrganizationList,
|
||||
&organizations.CmdOrganizationCreate,
|
||||
&organizations.CmdOrganizationDelete,
|
||||
@ -28,12 +30,12 @@ var CmdOrgs = cli.Command{
|
||||
Flags: organizations.CmdOrganizationList.Flags,
|
||||
}
|
||||
|
||||
func runOrganizations(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runOrganizationDetail(ctx)
|
||||
func runOrganizations(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
teaCtx := context.InitCommand(cmd)
|
||||
if teaCtx.Args().Len() == 1 {
|
||||
return runOrganizationDetail(teaCtx)
|
||||
}
|
||||
return organizations.RunOrganizationList(cmd)
|
||||
return organizations.RunOrganizationList(ctx, cmd)
|
||||
}
|
||||
|
||||
func runOrganizationDetail(ctx *context.TeaContext) error {
|
||||
|
@ -6,12 +6,13 @@ package organizations
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdOrganizationCreate represents a sub command of organizations to delete a given user organization
|
||||
@ -51,7 +52,7 @@ var CmdOrganizationCreate = cli.Command{
|
||||
}
|
||||
|
||||
// RunOrganizationCreate sets up a new organization
|
||||
func RunOrganizationCreate(cmd *cli.Context) error {
|
||||
func RunOrganizationCreate(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
|
||||
if ctx.Args().Len() < 1 {
|
||||
|
@ -4,11 +4,12 @@
|
||||
package organizations
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdOrganizationDelete represents a sub command of organizations to delete a given user organization
|
||||
@ -26,7 +27,7 @@ var CmdOrganizationDelete = cli.Command{
|
||||
}
|
||||
|
||||
// RunOrganizationDelete delete user organization
|
||||
func RunOrganizationDelete(cmd *cli.Context) error {
|
||||
func RunOrganizationDelete(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
|
||||
client := ctx.Login.Client()
|
||||
|
@ -4,12 +4,13 @@
|
||||
package organizations
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdOrganizationList represents a sub command of organizations to list users organizations
|
||||
@ -27,7 +28,7 @@ var CmdOrganizationList = cli.Command{
|
||||
}
|
||||
|
||||
// RunOrganizationList list user organizations
|
||||
func RunOrganizationList(cmd *cli.Context) error {
|
||||
func RunOrganizationList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
|
||||
|
15
cmd/pulls.go
15
cmd/pulls.go
@ -4,6 +4,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/pulls"
|
||||
@ -14,7 +15,7 @@ import (
|
||||
"code.gitea.io/tea/modules/workaround"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdPulls is the main command to operate on PRs
|
||||
@ -32,7 +33,7 @@ var CmdPulls = cli.Command{
|
||||
Usage: "Whether to display comments (will prompt if not provided & run interactively)",
|
||||
},
|
||||
}, pulls.CmdPullsList.Flags...),
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&pulls.CmdPullsList,
|
||||
&pulls.CmdPullsCheckout,
|
||||
&pulls.CmdPullsClean,
|
||||
@ -46,14 +47,14 @@ var CmdPulls = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func runPulls(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runPullDetail(ctx, ctx.Args().First())
|
||||
func runPulls(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
if cmd.Args().Len() == 1 {
|
||||
return runPullDetail(ctx, cmd, cmd.Args().First())
|
||||
}
|
||||
return pulls.RunPullsList(ctx)
|
||||
return pulls.RunPullsList(ctx, cmd)
|
||||
}
|
||||
|
||||
func runPullDetail(cmd *cli.Context, index string) error {
|
||||
func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
idx, err := utils.ArgToIndex(index)
|
||||
|
@ -7,13 +7,14 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdPullsApprove approves a PR
|
||||
@ -23,7 +24,7 @@ var CmdPullsApprove = cli.Command{
|
||||
Usage: "Approve a pull request",
|
||||
Description: "Approve a pull request",
|
||||
ArgsUsage: "<pull index> [<comment>]",
|
||||
Action: func(cmd *cli.Context) error {
|
||||
Action: func(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
package pulls
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdPullsCheckout is a command to locally checkout the given PR
|
||||
@ -32,7 +33,7 @@ var CmdPullsCheckout = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runPullsCheckout(cmd *cli.Context) error {
|
||||
func runPullsCheckout(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{
|
||||
LocalRepo: true,
|
||||
|
@ -6,13 +6,14 @@ package pulls
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdPullsClean removes the remote and local feature branches, if a PR is merged.
|
||||
@ -30,7 +31,7 @@ var CmdPullsClean = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runPullsClean(cmd *cli.Context) error {
|
||||
func runPullsClean(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{LocalRepo: true})
|
||||
if ctx.Args().Len() != 1 {
|
||||
|
@ -4,10 +4,12 @@
|
||||
package pulls
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdPullsClose closes a given open pull request
|
||||
@ -16,9 +18,9 @@ var CmdPullsClose = cli.Command{
|
||||
Usage: "Change state of one or more pull requests to 'closed'",
|
||||
Description: `Change state of one or more pull requests to 'closed'`,
|
||||
ArgsUsage: "<pull index> [<pull index>...]",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
var s = gitea.StateClosed
|
||||
return editPullState(ctx, gitea.EditPullRequestOption{State: &s})
|
||||
return editPullState(ctx, cmd, gitea.EditPullRequestOption{State: &s})
|
||||
},
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
@ -4,12 +4,13 @@
|
||||
package pulls
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdPullsCreate creates a pull request
|
||||
@ -38,7 +39,7 @@ var CmdPullsCreate = cli.Command{
|
||||
}, flags.IssuePRCreateFlags...),
|
||||
}
|
||||
|
||||
func runPullsCreate(cmd *cli.Context) error {
|
||||
func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
|
||||
// no args -> interactive mode
|
||||
|
@ -4,6 +4,7 @@
|
||||
package pulls
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/modules/context"
|
||||
@ -11,11 +12,11 @@ import (
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// editPullState abstracts the arg parsing to edit the given pull request
|
||||
func editPullState(cmd *cli.Context, opts gitea.EditPullRequestOption) error {
|
||||
func editPullState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditPullRequestOption) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
if ctx.Args().Len() == 0 {
|
||||
|
@ -4,12 +4,13 @@
|
||||
package pulls
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var pullFieldsFlag = flags.FieldsFlag(print.PullFields, []string{
|
||||
@ -28,7 +29,7 @@ var CmdPullsList = cli.Command{
|
||||
}
|
||||
|
||||
// RunPullsList return list of pulls
|
||||
func RunPullsList(cmd *cli.Context) error {
|
||||
func RunPullsList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,14 +4,15 @@
|
||||
package pulls
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdPullsMerge merges a PR
|
||||
@ -39,7 +40,7 @@ var CmdPullsMerge = cli.Command{
|
||||
Usage: "Merge commit message",
|
||||
},
|
||||
}, flags.AllDefaultFlags...),
|
||||
Action: func(cmd *cli.Context) error {
|
||||
Action: func(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
package pulls
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@ -13,7 +14,7 @@ import (
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdPullsReject requests changes to a PR
|
||||
@ -22,7 +23,7 @@ var CmdPullsReject = cli.Command{
|
||||
Usage: "Request changes to a pull request",
|
||||
Description: "Request changes to a pull request",
|
||||
ArgsUsage: "<pull index> <reason>",
|
||||
Action: func(cmd *cli.Context) error {
|
||||
Action: func(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,10 +4,12 @@
|
||||
package pulls
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdPullsReopen reopens a given closed pull request
|
||||
@ -17,9 +19,9 @@ var CmdPullsReopen = cli.Command{
|
||||
Usage: "Change state of one or more pull requests to 'open'",
|
||||
Description: `Change state of one or more pull requests to 'open'`,
|
||||
ArgsUsage: "<pull index> [<pull index>...]",
|
||||
Action: func(ctx *cli.Context) error {
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
var s = gitea.StateOpen
|
||||
return editPullState(ctx, gitea.EditPullRequestOption{State: &s})
|
||||
return editPullState(ctx, cmd, gitea.EditPullRequestOption{State: &s})
|
||||
},
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
package pulls
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdPullsReview starts an interactive review session
|
||||
@ -20,7 +21,7 @@ var CmdPullsReview = cli.Command{
|
||||
Usage: "Interactively review a pull request",
|
||||
Description: "Interactively review a pull request",
|
||||
ArgsUsage: "<pull index>",
|
||||
Action: func(cmd *cli.Context) error {
|
||||
Action: func(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/cmd/releases"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdReleases represents to login a gitea server.
|
||||
@ -20,7 +20,7 @@ var CmdReleases = cli.Command{
|
||||
Description: "Manage releases",
|
||||
ArgsUsage: " ", // command does not accept arguments
|
||||
Action: releases.RunReleasesList,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&releases.CmdReleaseList,
|
||||
&releases.CmdReleaseCreate,
|
||||
&releases.CmdReleaseDelete,
|
||||
|
@ -4,6 +4,7 @@
|
||||
package releases
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -13,7 +14,7 @@ import (
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdReleaseCreate represents a sub command of Release to create release
|
||||
@ -66,7 +67,7 @@ var CmdReleaseCreate = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleaseCreate(cmd *cli.Context) error {
|
||||
func runReleaseCreate(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,12 +4,13 @@
|
||||
package releases
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdReleaseDelete represents a sub command of Release to delete a release
|
||||
@ -33,7 +34,7 @@ var CmdReleaseDelete = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleaseDelete(cmd *cli.Context) error {
|
||||
func runReleaseDelete(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -7,11 +7,12 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdReleaseEdit represents a sub command of Release to edit releases
|
||||
@ -56,7 +57,7 @@ var CmdReleaseEdit = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleaseEdit(cmd *cli.Context) error {
|
||||
func runReleaseEdit(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -4,6 +4,7 @@
|
||||
package releases
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdReleaseList represents a sub command of Release to list releases
|
||||
@ -29,7 +30,7 @@ var CmdReleaseList = cli.Command{
|
||||
}
|
||||
|
||||
// RunReleasesList list releases
|
||||
func RunReleasesList(cmd *cli.Context) error {
|
||||
func RunReleasesList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
16
cmd/repos.go
16
cmd/repos.go
@ -4,13 +4,15 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/cmd/repos"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdRepos represents to login a gitea server.
|
||||
@ -22,7 +24,7 @@ var CmdRepos = cli.Command{
|
||||
Description: "Show repository details",
|
||||
ArgsUsage: "[<repo owner>/<repo name>]",
|
||||
Action: runRepos,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
&repos.CmdReposList,
|
||||
&repos.CmdReposSearch,
|
||||
&repos.CmdRepoCreate,
|
||||
@ -34,14 +36,14 @@ var CmdRepos = cli.Command{
|
||||
Flags: repos.CmdReposListFlags,
|
||||
}
|
||||
|
||||
func runRepos(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runRepoDetail(ctx, ctx.Args().First())
|
||||
func runRepos(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
if cmd.Args().Len() == 1 {
|
||||
return runRepoDetail(ctx, cmd, cmd.Args().First())
|
||||
}
|
||||
return repos.RunReposList(ctx)
|
||||
return repos.RunReposList(ctx, cmd)
|
||||
}
|
||||
|
||||
func runRepoDetail(cmd *cli.Context, path string) error {
|
||||
func runRepoDetail(_ stdctx.Context, cmd *cli.Command, path string) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
repoOwner, repoName := utils.GetOwnerAndRepo(path, ctx.Owner)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"code.gitea.io/tea/cmd/times"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdTrackedTimes represents the command to operate repositories' times.
|
||||
@ -19,7 +19,7 @@ var CmdTrackedTimes = cli.Command{
|
||||
times might be listed.`,
|
||||
ArgsUsage: "[username | #issue]",
|
||||
Action: times.RunTimesList,
|
||||
Subcommands: []*cli.Command{
|
||||
Commands: []*cli.Command{
|
||||
×.CmdTrackedTimesAdd,
|
||||
×.CmdTrackedTimesDelete,
|
||||
×.CmdTrackedTimesReset,
|
||||
|
@ -4,6 +4,7 @@
|
||||
package times
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@ -13,7 +14,7 @@ import (
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdTrackedTimesAdd represents a sub command of times to add time to an issue
|
||||
@ -30,7 +31,7 @@ var CmdTrackedTimesAdd = cli.Command{
|
||||
Flags: flags.LoginRepoFlags,
|
||||
}
|
||||
|
||||
func runTrackedTimesAdd(cmd *cli.Context) error {
|
||||
func runTrackedTimesAdd(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
package times
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
@ -11,7 +12,7 @@ import (
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdTrackedTimesDelete is a sub command of CmdTrackedTimes, and removes time from an issue
|
||||
@ -24,7 +25,7 @@ var CmdTrackedTimesDelete = cli.Command{
|
||||
Flags: flags.LoginRepoFlags,
|
||||
}
|
||||
|
||||
func runTrackedTimesDelete(cmd *cli.Context) error {
|
||||
func runTrackedTimesDelete(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -4,6 +4,7 @@
|
||||
package times
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@ -15,7 +16,7 @@ import (
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// NOTE: not using NewCsvFlag, as we don't want an alias & default value.
|
||||
@ -68,7 +69,7 @@ Depending on your permissions on the repository, only your own tracked times mig
|
||||
}
|
||||
|
||||
// RunTimesList list repositories
|
||||
func RunTimesList(cmd *cli.Context) error {
|
||||
func RunTimesList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -4,13 +4,14 @@
|
||||
package times
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdTrackedTimesReset is a subcommand of CmdTrackedTimes, and
|
||||
@ -23,7 +24,7 @@ var CmdTrackedTimesReset = cli.Command{
|
||||
Flags: flags.LoginRepoFlags,
|
||||
}
|
||||
|
||||
func runTrackedTimesReset(cmd *cli.Context) error {
|
||||
func runTrackedTimesReset(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
@ -4,10 +4,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdWhoami represents the command to show current logged in user
|
||||
@ -17,7 +18,7 @@ var CmdWhoami = cli.Command{
|
||||
Description: `For debugging purposes, show the user that is currently logged in.`,
|
||||
Usage: "Show current logged in user",
|
||||
ArgsUsage: " ", // command does not accept arguments
|
||||
Action: func(cmd *cli.Context) error {
|
||||
Action: func(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
user, _, _ := client.GetMyUserInfo()
|
||||
|
96
docs/CLI.md
96
docs/CLI.md
@ -6,11 +6,6 @@ tea - command line tool to interact with Gitea
|
||||
|
||||
tea
|
||||
|
||||
```
|
||||
[--help|-h]
|
||||
[--version|-v]
|
||||
```
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
tea is a productivity helper for Gitea. It can be used to manage most entities on
|
||||
@ -25,16 +20,9 @@ doing operations with tea. Configuration is persisted in $XDG_CONFIG_HOME/tea
|
||||
**Usage**:
|
||||
|
||||
```
|
||||
tea [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
|
||||
tea [GLOBAL OPTIONS] [command [COMMAND OPTIONS]] [ARGUMENTS...]
|
||||
```
|
||||
|
||||
# GLOBAL OPTIONS
|
||||
|
||||
**--help, -h**: show help
|
||||
|
||||
**--version, -v**: print the version
|
||||
|
||||
|
||||
# COMMANDS
|
||||
|
||||
## logins, login
|
||||
@ -79,7 +67,7 @@ Add a Gitea login
|
||||
|
||||
**--token, -t**="": Access token. Can be obtained from Settings > Applications
|
||||
|
||||
**--url, -u**="": Server URL (default: "https://gitea.com")
|
||||
**--url, -u**="": Server URL (default: https://gitea.com)
|
||||
|
||||
**--user**="": User for basic auth (will create token)
|
||||
|
||||
@ -129,13 +117,13 @@ List, create and update issues
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
index,state,kind,author,author-id,url,title,body,created,updated,deadline,assignees,milestone,labels,comments,owner,repo
|
||||
(default: "index,title,state,author,milestone,labels,owner,repo")
|
||||
(default: index,title,state,author,milestone,labels,owner,repo)
|
||||
|
||||
**--from, -F**="": Filter by activity after this date
|
||||
|
||||
**--keyword, -k**="": Filter by search string
|
||||
|
||||
**--kind, -K**="": Whether to return `issues`, `pulls`, or `all` (you can use this to apply advanced search filters to PRs) (default: issues)
|
||||
**--kind, -K**="": Whether to return `issues`, `pulls`, or `all` (you can use this to apply advanced search filters to PRs)
|
||||
|
||||
**--labels, -L**="": Comma-separated list of labels to match issues against.
|
||||
|
||||
@ -161,7 +149,7 @@ List, create and update issues
|
||||
|
||||
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||
|
||||
**--state**="": Filter by state (all|open|closed) (default: open)
|
||||
**--state**="": Filter by state (all|open|closed)
|
||||
|
||||
**--until, -u**="": Filter by activity before this date
|
||||
|
||||
@ -175,13 +163,13 @@ List issues of the repository
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
index,state,kind,author,author-id,url,title,body,created,updated,deadline,assignees,milestone,labels,comments,owner,repo
|
||||
(default: "index,title,state,author,milestone,labels,owner,repo")
|
||||
(default: index,title,state,author,milestone,labels,owner,repo)
|
||||
|
||||
**--from, -F**="": Filter by activity after this date
|
||||
|
||||
**--keyword, -k**="": Filter by search string
|
||||
|
||||
**--kind, -K**="": Whether to return `issues`, `pulls`, or `all` (you can use this to apply advanced search filters to PRs) (default: issues)
|
||||
**--kind, -K**="": Whether to return `issues`, `pulls`, or `all` (you can use this to apply advanced search filters to PRs)
|
||||
|
||||
**--labels, -L**="": Comma-separated list of labels to match issues against.
|
||||
|
||||
@ -207,7 +195,7 @@ List issues of the repository
|
||||
|
||||
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||
|
||||
**--state**="": Filter by state (all|open|closed) (default: open)
|
||||
**--state**="": Filter by state (all|open|closed)
|
||||
|
||||
**--until, -u**="": Filter by activity before this date
|
||||
|
||||
@ -293,7 +281,7 @@ Manage and checkout pull requests
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
index,state,author,author-id,url,title,body,mergeable,base,base-commit,head,diff,patch,created,updated,deadline,assignees,milestone,labels,comments
|
||||
(default: "index,title,state,author,milestone,updated,labels")
|
||||
(default: index,title,state,author,milestone,updated,labels)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -307,7 +295,7 @@ Manage and checkout pull requests
|
||||
|
||||
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||
|
||||
**--state**="": Filter by state (all|open|closed) (default: open)
|
||||
**--state**="": Filter by state (all|open|closed)
|
||||
|
||||
### list, ls
|
||||
|
||||
@ -315,7 +303,7 @@ List pull requests of the repository
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
index,state,author,author-id,url,title,body,mergeable,base,base-commit,head,diff,patch,created,updated,deadline,assignees,milestone,labels,comments
|
||||
(default: "index,title,state,author,milestone,updated,labels")
|
||||
(default: index,title,state,author,milestone,updated,labels)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -329,7 +317,7 @@ List pull requests of the repository
|
||||
|
||||
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||
|
||||
**--state**="": Filter by state (all|open|closed) (default: open)
|
||||
**--state**="": Filter by state (all|open|closed)
|
||||
|
||||
### checkout, co
|
||||
|
||||
@ -463,7 +451,7 @@ Merge a pull request
|
||||
|
||||
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||
|
||||
**--style, -s**="": Kind of merge to perform: merge, rebase, squash, rebase-merge (default: "merge")
|
||||
**--style, -s**="": Kind of merge to perform: merge, rebase, squash, rebase-merge (default: merge)
|
||||
|
||||
**--title, -t**="": Merge commit title
|
||||
|
||||
@ -563,7 +551,7 @@ List and create milestones
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
title,state,items_open,items_closed,items,duedate,description,created,updated,closed,id
|
||||
(default: "title,items,duedate")
|
||||
(default: title,items,duedate)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -577,7 +565,7 @@ List and create milestones
|
||||
|
||||
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||
|
||||
**--state**="": Filter by milestone state (all|open|closed) (default: open)
|
||||
**--state**="": Filter by milestone state (all|open|closed)
|
||||
|
||||
### list, ls
|
||||
|
||||
@ -585,7 +573,7 @@ List milestones of the repository
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
title,state,items_open,items_closed,items,duedate,description,created,updated,closed,id
|
||||
(default: "title,items,duedate")
|
||||
(default: title,items,duedate)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -599,7 +587,7 @@ List milestones of the repository
|
||||
|
||||
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||
|
||||
**--state**="": Filter by milestone state (all|open|closed) (default: open)
|
||||
**--state**="": Filter by milestone state (all|open|closed)
|
||||
|
||||
### create, c
|
||||
|
||||
@ -617,7 +605,7 @@ Create an milestone on repository
|
||||
|
||||
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||
|
||||
**--state**="": set milestone state (default is open) (default: open)
|
||||
**--state**="": set milestone state (default is open)
|
||||
|
||||
**--title, -t**="": milestone title to create
|
||||
|
||||
@ -665,7 +653,7 @@ manage issue/pull of an milestone
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
index,state,kind,author,author-id,url,title,body,created,updated,deadline,assignees,milestone,labels,comments,owner,repo
|
||||
(default: "index,kind,title,state,updated,labels")
|
||||
(default: index,kind,title,state,updated,labels)
|
||||
|
||||
**--kind**="": Filter by kind (issue|pull)
|
||||
|
||||
@ -681,7 +669,7 @@ manage issue/pull of an milestone
|
||||
|
||||
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||
|
||||
**--state**="": Filter by issue state (all|open|closed) (default: open)
|
||||
**--state**="": Filter by issue state (all|open|closed)
|
||||
|
||||
#### add, a
|
||||
|
||||
@ -739,7 +727,7 @@ List Releases
|
||||
|
||||
Create a release
|
||||
|
||||
**--asset, -a**="": Path to file attachment. Can be specified multiple times
|
||||
**--asset, -a**="": Path to file attachment. Can be specified multiple times (default: [])
|
||||
|
||||
**--draft, -d**: Is a draft
|
||||
|
||||
@ -783,7 +771,7 @@ Delete one or more releases
|
||||
|
||||
Edit one or more releases
|
||||
|
||||
**--draft, -d**="": Mark as Draft [True/false] (default: true)
|
||||
**--draft, -d**="": Mark as Draft [True/false]
|
||||
|
||||
**--login, -l**="": Use a different Gitea Login. Optional
|
||||
|
||||
@ -791,7 +779,7 @@ Edit one or more releases
|
||||
|
||||
**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json)
|
||||
|
||||
**--prerelease, -p**="": Mark as Pre-Release [True/false] (default: true)
|
||||
**--prerelease, -p**="": Mark as Pre-Release [True/false]
|
||||
|
||||
**--remote, -R**="": Discover Gitea login from remote. Optional
|
||||
|
||||
@ -1005,7 +993,7 @@ Show repository details
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
description,forks,id,name,owner,stars,ssh,updated,url,permission,type
|
||||
(default: "owner,name,type,ssh")
|
||||
(default: owner,name,type,ssh)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1027,7 +1015,7 @@ List repositories you have access to
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
description,forks,id,name,owner,stars,ssh,updated,url,permission,type
|
||||
(default: "owner,name,type,ssh")
|
||||
(default: owner,name,type,ssh)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1051,7 +1039,7 @@ Find any repo on an Gitea instance
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
description,forks,id,name,owner,stars,ssh,updated,url,permission,type
|
||||
(default: "owner,name,type,ssh")
|
||||
(default: owner,name,type,ssh)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1211,7 +1199,7 @@ Consult branches
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
name,protected,user-can-merge,user-can-push,protection
|
||||
(default: "name,protected,user-can-merge,user-can-push")
|
||||
(default: name,protected,user-can-merge,user-can-push)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1231,7 +1219,7 @@ List branches of the repository
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
name,protected,user-can-merge,user-can-push,protection
|
||||
(default: "name,protected,user-can-merge,user-can-push")
|
||||
(default: name,protected,user-can-merge,user-can-push)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1251,7 +1239,7 @@ Protect branches
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
name,protected,user-can-merge,user-can-push,protection
|
||||
(default: "name,protected,user-can-merge,user-can-push")
|
||||
(default: name,protected,user-can-merge,user-can-push)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1271,7 +1259,7 @@ Unprotect branches
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
name,protected,user-can-merge,user-can-push,protection
|
||||
(default: "name,protected,user-can-merge,user-can-push")
|
||||
(default: name,protected,user-can-merge,user-can-push)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1313,7 +1301,7 @@ Show notifications
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
id,status,updated,index,type,state,title,repository
|
||||
(default: "id,status,index,type,state,title")
|
||||
(default: id,status,index,type,state,title)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1331,7 +1319,7 @@ Show notifications
|
||||
|
||||
**--states, -s**="": Comma-separated list of notification states to filter by. Available values:
|
||||
pinned,unread,read
|
||||
(default: "unread,pinned")
|
||||
(default: unread,pinned)
|
||||
|
||||
**--types, -t**="": Comma-separated list of subject types to filter by. Available values:
|
||||
issue,pull,repository,commit
|
||||
@ -1343,7 +1331,7 @@ List notifications
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
id,status,updated,index,type,state,title,repository
|
||||
(default: "id,status,index,type,state,title")
|
||||
(default: id,status,index,type,state,title)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1361,7 +1349,7 @@ List notifications
|
||||
|
||||
**--states, -s**="": Comma-separated list of notification states to filter by. Available values:
|
||||
pinned,unread,read
|
||||
(default: "unread,pinned")
|
||||
(default: unread,pinned)
|
||||
|
||||
**--types, -t**="": Comma-separated list of subject types to filter by. Available values:
|
||||
issue,pull,repository,commit
|
||||
@ -1387,7 +1375,7 @@ Mark all filtered or a specific notification as read
|
||||
|
||||
**--states, -s**="": Comma-separated list of notification states to filter by. Available values:
|
||||
pinned,unread,read
|
||||
(default: "unread,pinned")
|
||||
(default: unread,pinned)
|
||||
|
||||
### unread, u
|
||||
|
||||
@ -1409,7 +1397,7 @@ Mark all filtered or a specific notification as unread
|
||||
|
||||
**--states, -s**="": Comma-separated list of notification states to filter by. Available values:
|
||||
pinned,unread,read
|
||||
(default: "unread,pinned")
|
||||
(default: unread,pinned)
|
||||
|
||||
### pin, p
|
||||
|
||||
@ -1431,7 +1419,7 @@ Mark all filtered or a specific notification as pinned
|
||||
|
||||
**--states, -s**="": Comma-separated list of notification states to filter by. Available values:
|
||||
pinned,unread,read
|
||||
(default: "unread,pinned")
|
||||
(default: unread,pinned)
|
||||
|
||||
### unpin
|
||||
|
||||
@ -1453,7 +1441,7 @@ Unpin all pinned or a specific notification
|
||||
|
||||
**--states, -s**="": Comma-separated list of notification states to filter by. Available values:
|
||||
pinned,unread,read
|
||||
(default: "unread,pinned")
|
||||
(default: unread,pinned)
|
||||
|
||||
## clone, C
|
||||
|
||||
@ -1473,7 +1461,7 @@ Manage registered users
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
id,login,full_name,email,avatar_url,language,is_admin,restricted,prohibit_login,location,website,description,visibility,activated,lastlogin_at,created_at
|
||||
(default: "id,login,full_name,email,activated")
|
||||
(default: id,login,full_name,email,activated)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1493,7 +1481,7 @@ List Users
|
||||
|
||||
**--fields, -f**="": Comma-separated list of fields to print. Available values:
|
||||
id,login,full_name,email,avatar_url,language,is_admin,restricted,prohibit_login,location,website,description,visibility,activated,lastlogin_at,created_at
|
||||
(default: "id,login,full_name,email,activated")
|
||||
(default: id,login,full_name,email,activated)
|
||||
|
||||
**--limit, --lm**="": specify limit of items per page
|
||||
|
||||
@ -1506,7 +1494,3 @@ List Users
|
||||
**--remote, -R**="": Discover Gitea login from remote. Optional
|
||||
|
||||
**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional
|
||||
|
||||
## help, h
|
||||
|
||||
Shows a list of commands or help for one command
|
||||
|
61
docs/docs.go
Normal file
61
docs/docs.go
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//go:generates
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"code.gitea.io/tea/cmd"
|
||||
docs "github.com/urfave/cli-docs/v3"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// CmdDocs generates markdown for tea
|
||||
func main() {
|
||||
cli := &cli.Command{
|
||||
Name: "docs",
|
||||
Hidden: true,
|
||||
Description: "Generate CLI docs",
|
||||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
|
||||
md, err := docs.ToMarkdown(cmd.App())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outPath := c.String("out")
|
||||
if outPath == "" {
|
||||
fmt.Print(md)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(outPath), os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fi, err := os.Create(outPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fi.Close()
|
||||
if _, err := fi.WriteString(md); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "out",
|
||||
Usage: "Path to output docs to, otherwise prints to stdout",
|
||||
Aliases: []string{"o"},
|
||||
},
|
||||
},
|
||||
}
|
||||
cli.Run(context.Background(), os.Args)
|
||||
}
|
4
go.mod
4
go.mod
@ -18,7 +18,8 @@ require (
|
||||
github.com/olekukonko/tablewriter v1.0.7
|
||||
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
|
||||
github.com/stretchr/testify v1.10.0
|
||||
github.com/urfave/cli/v2 v2.27.6
|
||||
github.com/urfave/cli-docs/v3 v3.0.0-alpha6
|
||||
github.com/urfave/cli/v3 v3.3.3
|
||||
golang.org/x/crypto v0.39.0
|
||||
golang.org/x/oauth2 v0.30.0
|
||||
golang.org/x/term v0.32.0
|
||||
@ -73,7 +74,6 @@ require (
|
||||
github.com/skeema/knownhosts v1.3.1 // indirect
|
||||
github.com/xanzy/ssh-agent v0.3.3 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||
github.com/yuin/goldmark v1.7.8 // indirect
|
||||
github.com/yuin/goldmark-emoji v1.0.5 // indirect
|
||||
golang.org/x/net v0.40.0 // indirect
|
||||
|
34
go.sum
34
go.sum
@ -86,8 +86,6 @@ github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UN
|
||||
github.com/go-git/go-billy/v5 v5.6.2/go.mod h1:rcFC2rAsp/erv7CMz9GczHcuD0D32fWzH+MJAU+jaUU=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
|
||||
github.com/go-git/go-git/v5 v5.16.0 h1:k3kuOEpkc0DeY7xlL6NaaNg39xdgQbtH5mwCafHO9AQ=
|
||||
github.com/go-git/go-git/v5 v5.16.0/go.mod h1:4Ge4alE/5gPs30F2H1esi2gPd69R0C39lolkucHBOp8=
|
||||
github.com/go-git/go-git/v5 v5.16.1 h1:TuxMBWNL7R05tXsUGi0kh1vi4tq0WfXNLlIrAkXG1k8=
|
||||
github.com/go-git/go-git/v5 v5.16.1/go.mod h1:4Ge4alE/5gPs30F2H1esi2gPd69R0C39lolkucHBOp8=
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
|
||||
@ -138,16 +136,8 @@ github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc
|
||||
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
||||
github.com/olekukonko/errors v1.1.0 h1:RNuGIh15QdDenh+hNvKrJkmxxjV4hcS50Db478Ou5sM=
|
||||
github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
|
||||
github.com/olekukonko/ll v0.0.6 h1:4CievQqZLsmHZ4whMgQ1qOyYbkhSEXAKlIru+phSq8Y=
|
||||
github.com/olekukonko/ll v0.0.6/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
|
||||
github.com/olekukonko/ll v0.0.7 h1:K66xcUlG2qWRhPoLw/cidmbv4pDDJtZuvJGsR5QTzXo=
|
||||
github.com/olekukonko/ll v0.0.7/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
|
||||
github.com/olekukonko/ll v0.0.8 h1:sbGZ1Fx4QxJXEqL/6IG8GEFnYojUSQ45dJVwN2FH2fc=
|
||||
github.com/olekukonko/ll v0.0.8/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
|
||||
github.com/olekukonko/tablewriter v1.0.4 h1:Lnz32TW+q/MQhA4qwhIyLA+j5hZ3dcNpZrcpPC+4iaM=
|
||||
github.com/olekukonko/tablewriter v1.0.4/go.mod h1:eUa4ArVhHJYomS27xrJB/GyLtnzKKVkZeLM6/MNO+pA=
|
||||
github.com/olekukonko/tablewriter v1.0.5 h1:8+uKJXxYcl29TcpfQdd0vL+l6Kul7Sk7sWolfgErDv0=
|
||||
github.com/olekukonko/tablewriter v1.0.5/go.mod h1:Z22i2ywMkT9sw64nuWAUaH62kb+umiwucGaQNbFh8Bg=
|
||||
github.com/olekukonko/tablewriter v1.0.7 h1:HCC2e3MM+2g72M81ZcJU11uciw6z/p82aEnm4/ySDGw=
|
||||
github.com/olekukonko/tablewriter v1.0.7/go.mod h1:H428M+HzoUXC6JU2Abj9IT9ooRmdq9CxuDmKMtrOCMs=
|
||||
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
|
||||
@ -183,14 +173,14 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/urfave/cli/v2 v2.27.6 h1:VdRdS98FNhKZ8/Az8B7MTyGQmpIr36O1EHybx/LaZ4g=
|
||||
github.com/urfave/cli/v2 v2.27.6/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
|
||||
github.com/urfave/cli-docs/v3 v3.0.0-alpha6 h1:w/l/N0xw1rO/aHRIGXJ0lDwwYFOzilup1qGvIytP3BI=
|
||||
github.com/urfave/cli-docs/v3 v3.0.0-alpha6/go.mod h1:p7Z4lg8FSTrPB9GTaNyTrK3ygffHZcK3w0cU2VE+mzU=
|
||||
github.com/urfave/cli/v3 v3.3.3 h1:byCBaVdIXuLPIDm5CYZRVG6NvT7tv1ECqdU4YzlEa3I=
|
||||
github.com/urfave/cli/v3 v3.3.3/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
|
||||
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
|
||||
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||
@ -204,24 +194,20 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
|
||||
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
|
||||
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
|
||||
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
|
||||
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
|
||||
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
|
||||
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
|
||||
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
|
||||
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
|
||||
@ -229,8 +215,8 @@ golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKl
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
|
||||
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
|
||||
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@ -254,16 +240,12 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
|
||||
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
|
||||
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
|
||||
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
123
main.go
123
main.go
@ -5,61 +5,16 @@
|
||||
package main // import "code.gitea.io/tea"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/cmd"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Version holds the current tea version
|
||||
var Version = "development"
|
||||
|
||||
// Tags holds the build tags used
|
||||
var Tags = ""
|
||||
|
||||
// SDK holds the sdk version from go.mod
|
||||
var SDK = ""
|
||||
|
||||
func main() {
|
||||
// make parsing tea --version easier, by printing /just/ the version string
|
||||
cli.VersionPrinter = func(c *cli.Context) { fmt.Fprintln(c.App.Writer, c.App.Version) }
|
||||
|
||||
app := cli.NewApp()
|
||||
app.Name = "tea"
|
||||
app.Usage = "command line tool to interact with Gitea"
|
||||
app.Description = appDescription
|
||||
app.CustomAppHelpTemplate = helpTemplate
|
||||
app.Version = formatVersion()
|
||||
app.Commands = []*cli.Command{
|
||||
&cmd.CmdLogin,
|
||||
&cmd.CmdLogout,
|
||||
&cmd.CmdAutocomplete,
|
||||
&cmd.CmdWhoami,
|
||||
|
||||
&cmd.CmdIssues,
|
||||
&cmd.CmdPulls,
|
||||
&cmd.CmdLabels,
|
||||
&cmd.CmdMilestones,
|
||||
&cmd.CmdReleases,
|
||||
&cmd.CmdTrackedTimes,
|
||||
&cmd.CmdOrgs,
|
||||
&cmd.CmdRepos,
|
||||
&cmd.CmdBranches,
|
||||
&cmd.CmdAddComment,
|
||||
|
||||
&cmd.CmdOpen,
|
||||
&cmd.CmdNotifications,
|
||||
&cmd.CmdRepoClone,
|
||||
|
||||
&cmd.CmdAdmin,
|
||||
&cmd.CmdDocs,
|
||||
}
|
||||
app.EnableBashCompletion = true
|
||||
err := app.Run(os.Args)
|
||||
app := cmd.App()
|
||||
err := app.Run(context.Background(), os.Args)
|
||||
if err != nil {
|
||||
// app.Run already exits for errors implementing ErrorCoder,
|
||||
// so we only handle generic errors with code 1 here.
|
||||
@ -67,75 +22,3 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func formatVersion() string {
|
||||
version := fmt.Sprintf("Version: %s\tgolang: %s",
|
||||
bold(Version),
|
||||
strings.ReplaceAll(runtime.Version(), "go", ""))
|
||||
|
||||
if len(Tags) != 0 {
|
||||
version += fmt.Sprintf("\tbuilt with: %s", strings.Replace(Tags, " ", ", ", -1))
|
||||
}
|
||||
|
||||
if len(SDK) != 0 {
|
||||
version += fmt.Sprintf("\tgo-sdk: %s", SDK)
|
||||
}
|
||||
|
||||
return version
|
||||
}
|
||||
|
||||
var appDescription = `tea is a productivity helper for Gitea. It can be used to manage most entities on
|
||||
one or multiple Gitea instances & provides local helpers like 'tea pr checkout'.
|
||||
|
||||
tea tries to make use of context provided by the repository in $PWD if available.
|
||||
tea works best in a upstream/fork workflow, when the local main branch tracks the
|
||||
upstream repo. tea assumes that local git state is published on the remote before
|
||||
doing operations with tea. Configuration is persisted in $XDG_CONFIG_HOME/tea.
|
||||
`
|
||||
|
||||
var helpTemplate = bold(`
|
||||
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}`) + `
|
||||
{{if .Version}}{{if not .HideVersion}}version {{.Version}}{{end}}{{end}}
|
||||
|
||||
USAGE
|
||||
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .Commands}} command [subcommand] [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}}
|
||||
|
||||
DESCRIPTION
|
||||
{{.Description | nindent 3 | trim}}{{end}}{{if .VisibleCommands}}
|
||||
|
||||
COMMANDS{{range .VisibleCategories}}{{if .Name}}
|
||||
{{.Name}}:{{range .VisibleCommands}}
|
||||
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
|
||||
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
|
||||
|
||||
OPTIONS
|
||||
{{range $index, $option := .VisibleFlags}}{{if $index}}
|
||||
{{end}}{{$option}}{{end}}{{end}}
|
||||
|
||||
EXAMPLES
|
||||
tea login add # add a login once to get started
|
||||
|
||||
tea pulls # list open pulls for the repo in $PWD
|
||||
tea pulls --repo $HOME/foo # list open pulls for the repo in $HOME/foo
|
||||
tea pulls --remote upstream # list open pulls for the repo pointed at by
|
||||
# your local "upstream" git remote
|
||||
# list open pulls for any gitea repo at the given login instance
|
||||
tea pulls --repo gitea/tea --login gitea.com
|
||||
|
||||
tea milestone issues 0.7.0 # view open issues for milestone '0.7.0'
|
||||
tea issue 189 # view contents of issue 189
|
||||
tea open 189 # open web ui for issue 189
|
||||
tea open milestones # open web ui for milestones
|
||||
|
||||
# send gitea desktop notifications every 5 minutes (bash + libnotify)
|
||||
while :; do tea notifications --mine -o simple | xargs -i notify-send {}; sleep 300; done
|
||||
|
||||
ABOUT
|
||||
Written & maintained by The Gitea Authors.
|
||||
If you find a bug or want to contribute, we'll welcome you at https://gitea.com/gitea/tea.
|
||||
More info about Gitea itself on https://about.gitea.com.
|
||||
`
|
||||
|
||||
func bold(t string) string {
|
||||
return fmt.Sprintf("\033[1m%s\033[0m", t)
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
gogit "github.com/go-git/go-git/v5"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -26,7 +26,7 @@ var (
|
||||
|
||||
// TeaContext contains all context derived during command initialization and wraps cli.Context
|
||||
type TeaContext struct {
|
||||
*cli.Context
|
||||
*cli.Command
|
||||
Login *config.Login // config data & client for selected login
|
||||
RepoSlug string // <owner>/<repo>, optional
|
||||
Owner string // repo owner as derived from context or provided in flag, optional
|
||||
@ -83,11 +83,11 @@ type CtxRequirement struct {
|
||||
// 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(ctx *cli.Context) *TeaContext {
|
||||
func InitCommand(cmd *cli.Command) *TeaContext {
|
||||
// these flags are used as overrides to the context detection via local git repo
|
||||
repoFlag := ctx.String("repo")
|
||||
loginFlag := ctx.String("login")
|
||||
remoteFlag := ctx.String("remote")
|
||||
repoFlag := cmd.String("repo")
|
||||
loginFlag := cmd.String("login")
|
||||
remoteFlag := cmd.String("remote")
|
||||
|
||||
var (
|
||||
c TeaContext
|
||||
@ -147,9 +147,8 @@ and then run your command again.`)
|
||||
|
||||
// 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.Context = ctx
|
||||
c.Output = ctx.String("output")
|
||||
c.Command = cmd
|
||||
c.Output = cmd.String("output")
|
||||
return &c
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user