Skip to content

Commit

Permalink
Migrate to github.com/urfave/cli/v3 (#2951)
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 authored Jul 17, 2024
1 parent e393456 commit cd5f6f7
Show file tree
Hide file tree
Showing 112 changed files with 823 additions and 679 deletions.
4 changes: 2 additions & 2 deletions cli/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package admin

import (
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/cli/admin/registry"
)
Expand All @@ -24,7 +24,7 @@ import (
var Command = &cli.Command{
Name: "admin",
Usage: "administer server settings",
Subcommands: []*cli.Command{
Commands: []*cli.Command{
registry.Command,
},
}
4 changes: 2 additions & 2 deletions cli/admin/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
package registry

import (
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

// Command exports the registry command set.
var Command = &cli.Command{
Name: "registry",
Usage: "manage global registries",
Subcommands: []*cli.Command{
Commands: []*cli.Command{
registryCreateCmd,
registryDeleteCmd,
registryUpdateCmd,
Expand Down
7 changes: 4 additions & 3 deletions cli/admin/registry/registry_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package registry

import (
"context"
"os"
"strings"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
"go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker"
Expand All @@ -45,14 +46,14 @@ var registryCreateCmd = &cli.Command{
},
}

func registryCreate(c *cli.Context) error {
func registryCreate(ctx context.Context, c *cli.Command) error {
var (
hostname = c.String("hostname")
username = c.String("username")
password = c.String("password")
)

client, err := internal.NewClient(c)
client, err := internal.NewClient(ctx, c)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cli/admin/registry/registry_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package registry

import (
"context"
"html/template"
"os"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/cli/common"
"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
Expand All @@ -38,13 +39,13 @@ var registryInfoCmd = &cli.Command{
},
}

func registryInfo(c *cli.Context) error {
func registryInfo(ctx context.Context, c *cli.Command) error {
var (
hostname = c.String("hostname")
format = c.String("format") + "\n"
)

client, err := internal.NewClient(c)
client, err := internal.NewClient(ctx, c)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cli/admin/registry/registry_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package registry

import (
"context"
"html/template"
"os"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/cli/common"
"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
Expand All @@ -33,10 +34,10 @@ var registryListCmd = &cli.Command{
},
}

func registryList(c *cli.Context) error {
func registryList(ctx context.Context, c *cli.Command) error {
format := c.String("format") + "\n"

client, err := internal.NewClient(c)
client, err := internal.NewClient(ctx, c)
if err != nil {
return err
}
Expand Down
8 changes: 5 additions & 3 deletions cli/admin/registry/registry_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package registry

import (
"github.com/urfave/cli/v2"
"context"

"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
)
Expand All @@ -33,10 +35,10 @@ var registryDeleteCmd = &cli.Command{
},
}

func registryDelete(c *cli.Context) error {
func registryDelete(ctx context.Context, c *cli.Command) error {
hostname := c.String("hostname")

client, err := internal.NewClient(c)
client, err := internal.NewClient(ctx, c)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cli/admin/registry/registry_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package registry

import (
"context"
"os"
"strings"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/cli/common"
"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
Expand Down Expand Up @@ -47,14 +48,14 @@ var registryUpdateCmd = &cli.Command{
},
}

func registryUpdate(c *cli.Context) error {
func registryUpdate(ctx context.Context, c *cli.Command) error {
var (
hostname = c.String("hostname")
username = c.String("username")
password = c.String("password")
)

client, err := internal.NewClient(c)
client, err := internal.NewClient(ctx, c)
if err != nil {
return err
}
Expand Down
16 changes: 8 additions & 8 deletions cli/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,49 @@
package common

import (
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/shared/logger"
)

var GlobalFlags = append([]cli.Flag{
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_CONFIG"},
Sources: cli.EnvVars("WOODPECKER_CONFIG"),
Name: "config",
Aliases: []string{"c"},
Usage: "path to config file",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_SERVER"},
Sources: cli.EnvVars("WOODPECKER_SERVER"),
Name: "server",
Aliases: []string{"s"},
Usage: "server address",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_TOKEN"},
Sources: cli.EnvVars("WOODPECKER_TOKEN"),
Name: "token",
Aliases: []string{"t"},
Usage: "server auth token",
},
&cli.BoolFlag{
EnvVars: []string{"WOODPECKER_DISABLE_UPDATE_CHECK"},
Sources: cli.EnvVars("WOODPECKER_DISABLE_UPDATE_CHECK"),
Name: "disable-update-check",
Usage: "disable update check",
},
&cli.BoolFlag{
EnvVars: []string{"WOODPECKER_SKIP_VERIFY"},
Sources: cli.EnvVars("WOODPECKER_SKIP_VERIFY"),
Name: "skip-verify",
Usage: "skip ssl verification",
Hidden: true,
},
&cli.StringFlag{
EnvVars: []string{"SOCKS_PROXY"},
Sources: cli.EnvVars("SOCKS_PROXY"),
Name: "socks-proxy",
Usage: "socks proxy address",
Hidden: true,
},
&cli.BoolFlag{
EnvVars: []string{"SOCKS_PROXY_OFF"},
Sources: cli.EnvVars("SOCKS_PROXY_OFF"),
Name: "socks-proxy-off",
Usage: "socks proxy ignored",
Hidden: true,
Expand Down
18 changes: 9 additions & 9 deletions cli/common/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/cli/internal/config"
"go.woodpecker-ci.org/woodpecker/v2/cli/update"
Expand All @@ -17,12 +17,12 @@ var (
cancelWaitForUpdate context.CancelCauseFunc
)

func Before(c *cli.Context) error {
if err := setupGlobalLogger(c); err != nil {
func Before(ctx context.Context, c *cli.Command) error {
if err := setupGlobalLogger(ctx, c); err != nil {
return err
}

go func() {
go func(context.Context) {
if c.Bool("disable-update-check") {
return
}
Expand All @@ -37,23 +37,23 @@ func Before(c *cli.Context) error {

log.Debug().Msg("Checking for updates ...")

newVersion, err := update.CheckForUpdate(waitForUpdateCheck, false)
newVersion, err := update.CheckForUpdate(waitForUpdateCheck, false) //nolint:contextcheck
if err != nil {
log.Error().Err(err).Msgf("Failed to check for updates")
return
}

if newVersion != nil {
log.Warn().Msgf("A new version of woodpecker-cli is available: %s. Update by running: %s update", newVersion.Version, c.App.Name)
log.Warn().Msgf("A new version of woodpecker-cli is available: %s. Update by running: %s update", newVersion.Version, c.Root().Name)
} else {
log.Debug().Msgf("No update required")
}
}()
}(ctx)

return config.Load(c)
return config.Load(ctx, c)
}

func After(_ *cli.Context) error {
func After(_ context.Context, _ *cli.Command) error {
if waitForUpdateCheck != nil {
select {
case <-waitForUpdateCheck.Done():
Expand Down
13 changes: 7 additions & 6 deletions cli/common/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
package common

import (
"context"
"fmt"
"os"
"strings"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/shared/constant"
)
Expand All @@ -37,16 +38,16 @@ func DetectPipelineConfig() (isDir bool, config string, _ error) {
return false, "", fmt.Errorf("could not detect pipeline config")
}

func RunPipelineFunc(c *cli.Context, fileFunc, dirFunc func(*cli.Context, string) error) error {
func RunPipelineFunc(ctx context.Context, c *cli.Command, fileFunc, dirFunc func(context.Context, *cli.Command, string) error) error {
if c.Args().Len() == 0 {
isDir, path, err := DetectPipelineConfig()
if err != nil {
return err
}
if isDir {
return dirFunc(c, path)
return dirFunc(ctx, c, path)
}
return fileFunc(c, path)
return fileFunc(ctx, c, path)
}

multiArgs := c.Args().Len() > 1
Expand All @@ -59,11 +60,11 @@ func RunPipelineFunc(c *cli.Context, fileFunc, dirFunc func(*cli.Context, string
fmt.Println("#", fi.Name())
}
if fi.IsDir() {
if err := dirFunc(c, arg); err != nil {
if err := dirFunc(ctx, c, arg); err != nil {
return err
}
} else {
if err := fileFunc(c, arg); err != nil {
if err := fileFunc(ctx, c, arg); err != nil {
return err
}
}
Expand Down
8 changes: 5 additions & 3 deletions cli/common/zerologger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package common

import (
"github.com/urfave/cli/v2"
"context"

"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/shared/logger"
)

func setupGlobalLogger(c *cli.Context) error {
return logger.SetupGlobalLogger(c, false)
func setupGlobalLogger(ctx context.Context, c *cli.Command) error {
return logger.SetupGlobalLogger(ctx, c, false)
}
4 changes: 2 additions & 2 deletions cli/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
package cron

import (
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

// Command exports the cron command set.
var Command = &cli.Command{
Name: "cron",
Usage: "manage cron jobs",
Subcommands: []*cli.Command{
Commands: []*cli.Command{
cronCreateCmd,
cronDeleteCmd,
cronUpdateCmd,
Expand Down
Loading

0 comments on commit cd5f6f7

Please sign in to comment.