build: bump urfave/cli v3

main
sudo pacman -Syu 2025-04-06 10:35:30 +07:00
parent f704605752
commit 0527e742c1
7 changed files with 38 additions and 44 deletions

View File

@ -21,7 +21,7 @@ func main() {
app := cli.NewApp(
initGitHubClient(),
)
app.Run()
app.Run(context.Background())
}
func initGitHubClient() *github.Client {

5
go.mod
View File

@ -9,22 +9,19 @@ require (
github.com/make-go-great/netrc-go v0.0.2
github.com/sourcegraph/conc v0.3.0
github.com/spf13/cast v1.7.1
github.com/urfave/cli/v2 v2.27.6
github.com/urfave/cli/v3 v3.1.1
golang.org/x/oauth2 v0.28.0
)
require (
github.com/bytedance/sonic/loader v0.2.4 // indirect
github.com/cloudwego/base64x v0.1.5 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect

14
go.sum
View File

@ -6,8 +6,6 @@ github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFos
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -42,8 +40,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
@ -56,14 +52,12 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
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/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
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/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/urfave/cli/v3 v3.1.1 h1:bNnl8pFI5dxPOjeONvFCDFoECLQsceDG4ejahs4Jtxk=
github.com/urfave/cli/v3 v3.1.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=

View File

@ -1,10 +1,11 @@
package cli
import (
"context"
"log"
"github.com/google/go-github/v70/github"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
const (
@ -22,11 +23,11 @@ type action struct {
}
}
func (a *action) RunHelp(c *cli.Context) error {
func (a *action) RunHelp(ctx context.Context, c *cli.Command) error {
return cli.ShowAppHelp(c)
}
func (a *action) getFlags(c *cli.Context) {
func (a *action) getFlags(c *cli.Command) {
a.flags.verbose = c.Bool(flagVerboseName)
a.flags.depsFile = c.String(flagDepsFileName)

View File

@ -13,7 +13,7 @@ import (
"github.com/google/go-github/v70/github"
"github.com/sourcegraph/conc/pool"
"github.com/spf13/cast"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)
const maxPoolGoroutine = 8
@ -26,7 +26,7 @@ type GitHubRepoData struct {
StarCount int
}
func (a *action) Overlook(c *cli.Context) error {
func (a *action) Overlook(ctx context.Context, c *cli.Command) error {
// Optional
if a.ghClient == nil {
return nil
@ -34,7 +34,7 @@ func (a *action) Overlook(c *cli.Context) error {
a.getFlags(c)
mapImportedModules, err := a.runGetImportedModules(c)
mapImportedModules, err := a.runGetImportedModules(ctx)
if err != nil {
return err
}

View File

@ -1,6 +1,7 @@
package cli
import (
"context"
"errors"
"fmt"
"io"
@ -11,7 +12,7 @@ import (
"strings"
"github.com/bytedance/sonic"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
"github.com/make-go-great/color-go"
)
@ -33,10 +34,10 @@ var (
ErrGoModExistToolchain = errors.New("go mod exist toolchain")
)
func (a *action) Run(c *cli.Context) error {
func (a *action) Run(ctx context.Context, c *cli.Command) error {
a.getFlags(c)
mapImportedModules, err := a.runGetImportedModules(c)
mapImportedModules, err := a.runGetImportedModules(ctx)
if err != nil {
return err
}
@ -61,7 +62,7 @@ func (a *action) Run(c *cli.Context) error {
modulePaths := strings.SplitSeq(depsStr, "\n")
for modulePath := range modulePaths {
successUpgradedModules, err = a.runUpgradeModule(
c,
ctx,
mapImportedModules,
successUpgradedModules,
modulePath,
@ -71,11 +72,11 @@ func (a *action) Run(c *cli.Context) error {
}
}
if err := a.runGoMod(c, existVendor); err != nil {
if err := a.runGoMod(ctx, existVendor); err != nil {
return err
}
if err := a.runGitCommit(c, successUpgradedModules, existVendor, useDepFile); err != nil {
if err := a.runGitCommit(ctx, successUpgradedModules, existVendor, useDepFile); err != nil {
return err
}
@ -83,9 +84,9 @@ func (a *action) Run(c *cli.Context) error {
}
// Get all imported modules
func (a *action) runGetImportedModules(c *cli.Context) (map[string]*Module, error) {
func (a *action) runGetImportedModules(ctx context.Context) (map[string]*Module, error) {
goListAllArgs := []string{"list", "-m", "-json", "-mod=readonly", "all"}
goOutput, err := exec.CommandContext(c.Context, "go", goListAllArgs...).CombinedOutput()
goOutput, err := exec.CommandContext(ctx, "go", goListAllArgs...).CombinedOutput()
if err != nil {
return nil, fmt.Errorf("exec: failed to run go %s: %w", strings.Join(goListAllArgs, " "), err)
}
@ -169,7 +170,7 @@ func (a *action) runReadDepsFile() (depsStr string, useDepFile bool, err error)
}
func (a *action) runUpgradeModule(
c *cli.Context,
ctx context.Context,
mapImportedModules map[string]*Module,
successUpgradedModules []*Module,
modulePath string,
@ -196,7 +197,7 @@ func (a *action) runUpgradeModule(
// Get module latest version
goListArgs := []string{"list", "-m", "-u", "-json", "-mod=readonly", modulePath}
goOutput, err := exec.CommandContext(c.Context, "go", goListArgs...).CombinedOutput()
goOutput, err := exec.CommandContext(ctx, "go", goListArgs...).CombinedOutput()
if err != nil {
return successUpgradedModules, fmt.Errorf("exec: failed to run go %+v: %w", strings.Join(goListArgs, " "), err)
}
@ -222,7 +223,7 @@ func (a *action) runUpgradeModule(
}
goGetArgs := []string{"get", modulePath + "@" + module.Update.Version}
goOutput, err = exec.CommandContext(c.Context, "go", goGetArgs...).CombinedOutput()
goOutput, err = exec.CommandContext(ctx, "go", goGetArgs...).CombinedOutput()
if err != nil {
return successUpgradedModules, fmt.Errorf("exec: failed to run go %+v: %w", strings.Join(goGetArgs, " "), err)
}
@ -235,20 +236,20 @@ func (a *action) runUpgradeModule(
return successUpgradedModules, nil
}
func (a *action) runGoMod(c *cli.Context, existVendor bool) error {
func (a *action) runGoMod(ctx context.Context, existVendor bool) error {
if a.flags.dryRun {
return nil
}
// go mod edit -toolchain=none
goModArgs := []string{"mod", "edit", "-toolchain=none"}
if _, err := exec.CommandContext(c.Context, "go", goModArgs...).CombinedOutput(); err != nil {
if _, err := exec.CommandContext(ctx, "go", goModArgs...).CombinedOutput(); err != nil {
return fmt.Errorf("exec: failed to run go %+v: %w", strings.Join(goModArgs, " "), err)
}
// go mod tidy
goModArgs = []string{"mod", "tidy"}
goOutput, err := exec.CommandContext(c.Context, "go", goModArgs...).CombinedOutput()
goOutput, err := exec.CommandContext(ctx, "go", goModArgs...).CombinedOutput()
if err != nil {
return fmt.Errorf("exec: failed to run go %+v: %w", strings.Join(goModArgs, " "), err)
}
@ -257,7 +258,7 @@ func (a *action) runGoMod(c *cli.Context, existVendor bool) error {
if existVendor {
// go mod vendor
goModArgs = []string{"mod", "vendor"}
goOutput, err = exec.CommandContext(c.Context, "go", goModArgs...).CombinedOutput()
goOutput, err = exec.CommandContext(ctx, "go", goModArgs...).CombinedOutput()
if err != nil {
return fmt.Errorf("exec: failed to run go %+v: %w", strings.Join(goModArgs, " "), err)
}
@ -292,7 +293,7 @@ func (a *action) runReadGoMod() (*GoMod, error) {
return goMod, nil
}
func (a *action) runGitCommit(c *cli.Context, successUpgradedModules []*Module, existVendor, useDepFile bool) error {
func (a *action) runGitCommit(ctx context.Context, successUpgradedModules []*Module, existVendor, useDepFile bool) error {
if a.flags.dryRun {
return nil
}
@ -320,7 +321,7 @@ func (a *action) runGitCommit(c *cli.Context, successUpgradedModules []*Module,
gitAddArgs = append(gitAddArgs, a.flags.depsFile)
}
gitOutput, err := exec.CommandContext(c.Context, "git", gitAddArgs...).CombinedOutput()
gitOutput, err := exec.CommandContext(ctx, "git", gitAddArgs...).CombinedOutput()
if err != nil {
return fmt.Errorf("exec: failed to run git %+v: %w", strings.Join(gitAddArgs, " "), err)
}
@ -332,7 +333,7 @@ func (a *action) runGitCommit(c *cli.Context, successUpgradedModules []*Module,
gitCommitMessage += fmt.Sprintf("\n%s: %s -> %s", module.Path, module.Version, module.Update.Version)
}
gitCommitArgs := []string{"commit", "-m", gitCommitMessage}
gitOutput, err = exec.CommandContext(c.Context, "git", gitCommitArgs...).CombinedOutput()
gitOutput, err = exec.CommandContext(ctx, "git", gitCommitArgs...).CombinedOutput()
if err != nil {
return fmt.Errorf("exec: failed to run git %+v: %w", strings.Join(gitCommitArgs, " "), err)
}

View File

@ -1,10 +1,11 @@
package cli
import (
"context"
"os"
"github.com/google/go-github/v70/github"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
"github.com/make-go-great/color-go"
)
@ -38,7 +39,7 @@ const (
var aliasFlagVerbose = []string{"v"}
type App struct {
cliApp *cli.App
cliApp *cli.Command
}
func NewApp(
@ -48,7 +49,7 @@ func NewApp(
ghClient: ghClient,
}
cliApp := &cli.App{
cliApp := &cli.Command{
Name: name,
Usage: usage,
Commands: []*cli.Command{
@ -101,8 +102,8 @@ func NewApp(
}
}
func (a *App) Run() {
if err := a.cliApp.Run(os.Args); err != nil {
func (a *App) Run(ctx context.Context) {
if err := a.cliApp.Run(ctx, os.Args); err != nil {
color.PrintAppError(name, err.Error())
}
}