Unify cli commands and flags (#4481)

- Unify command and flag descriptions
- Unify logs
- Rename `woodpecker-cli [registry|ssecret|...] info` commands to `woodpecker-cli [registry|ssecret|...] show`
This commit is contained in:
Robert Kaussow 2024-11-30 15:23:44 +01:00 committed by GitHub
parent 9a8d7d8838
commit 57e7572b6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
43 changed files with 119 additions and 118 deletions

View File

@ -29,7 +29,7 @@ import (
var Command = &cli.Command{ var Command = &cli.Command{
Name: "log-level", Name: "log-level",
ArgsUsage: "[level]", ArgsUsage: "[level]",
Usage: "get the logging level of the server, or set it with [level]", Usage: "retrieve log level from server, or set it with [level]",
Action: logLevel, Action: logLevel,
} }
@ -59,6 +59,6 @@ func logLevel(ctx context.Context, c *cli.Command) error {
} }
} }
log.Info().Msgf("logging level: %s", ll.Level) log.Info().Msgf("log level: %s", ll.Level)
return nil return nil
} }

View File

@ -26,7 +26,7 @@ var Command = &cli.Command{
registryCreateCmd, registryCreateCmd,
registryDeleteCmd, registryDeleteCmd,
registryUpdateCmd, registryUpdateCmd,
registryInfoCmd, registryShowCmd,
registryListCmd, registryListCmd,
}, },
} }

View File

@ -27,7 +27,7 @@ import (
var registryCreateCmd = &cli.Command{ var registryCreateCmd = &cli.Command{
Name: "add", Name: "add",
Usage: "adds a registry", Usage: "add a registry",
Action: registryCreate, Action: registryCreate,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{

View File

@ -25,10 +25,10 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal" "go.woodpecker-ci.org/woodpecker/v2/cli/internal"
) )
var registryInfoCmd = &cli.Command{ var registryShowCmd = &cli.Command{
Name: "info", Name: "show",
Usage: "display registry info", Usage: "show registry information",
Action: registryInfo, Action: registryShow,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "hostname", Name: "hostname",
@ -39,7 +39,7 @@ var registryInfoCmd = &cli.Command{
}, },
} }
func registryInfo(ctx context.Context, c *cli.Command) error { func registryShow(ctx context.Context, c *cli.Command) error {
var ( var (
hostname = c.String("hostname") hostname = c.String("hostname")
format = c.String("format") + "\n" format = c.String("format") + "\n"

View File

@ -26,7 +26,7 @@ var Command = &cli.Command{
secretCreateCmd, secretCreateCmd,
secretDeleteCmd, secretDeleteCmd,
secretUpdateCmd, secretUpdateCmd,
secretInfoCmd, secretShowCmd,
secretListCmd, secretListCmd,
}, },
} }

View File

@ -27,7 +27,7 @@ import (
var secretCreateCmd = &cli.Command{ var secretCreateCmd = &cli.Command{
Name: "add", Name: "add",
Usage: "adds a secret", Usage: "add a secret",
ArgsUsage: "[repo-id|repo-full-name]", ArgsUsage: "[repo-id|repo-full-name]",
Action: secretCreate, Action: secretCreate,
Flags: []cli.Flag{ Flags: []cli.Flag{

View File

@ -26,11 +26,11 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal" "go.woodpecker-ci.org/woodpecker/v2/cli/internal"
) )
var secretInfoCmd = &cli.Command{ var secretShowCmd = &cli.Command{
Name: "info", Name: "show",
Usage: "display secret info", Usage: "show secret information",
ArgsUsage: "[repo-id|repo-full-name]", ArgsUsage: "[repo-id|repo-full-name]",
Action: secretInfo, Action: secretShow,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "name", Name: "name",
@ -40,7 +40,7 @@ var secretInfoCmd = &cli.Command{
}, },
} }
func secretInfo(ctx context.Context, c *cli.Command) error { func secretShow(ctx context.Context, c *cli.Command) error {
var ( var (
secretName = c.String("name") secretName = c.String("name")
format = c.String("format") + "\n" format = c.String("format") + "\n"

View File

@ -24,7 +24,7 @@ var Command = &cli.Command{
Usage: "manage users", Usage: "manage users",
Commands: []*cli.Command{ Commands: []*cli.Command{
userListCmd, userListCmd,
userInfoCmd, userShowCmd,
userAddCmd, userAddCmd,
userRemoveCmd, userRemoveCmd,
}, },

View File

@ -26,7 +26,7 @@ import (
var userAddCmd = &cli.Command{ var userAddCmd = &cli.Command{
Name: "add", Name: "add",
Usage: "adds a user", Usage: "add a user",
ArgsUsage: "<username>", ArgsUsage: "<username>",
Action: userAdd, Action: userAdd,
} }

View File

@ -26,15 +26,15 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal" "go.woodpecker-ci.org/woodpecker/v2/cli/internal"
) )
var userInfoCmd = &cli.Command{ var userShowCmd = &cli.Command{
Name: "info", Name: "show",
Usage: "show user details", Usage: "show user information",
ArgsUsage: "<username>", ArgsUsage: "<username>",
Action: userInfo, Action: userShow,
Flags: []cli.Flag{common.FormatFlag(tmplUserInfo)}, Flags: []cli.Flag{common.FormatFlag(tmplUserInfo)},
} }
func userInfo(ctx context.Context, c *cli.Command) error { func userShow(ctx context.Context, c *cli.Command) error {
client, err := internal.NewClient(ctx, c) client, err := internal.NewClient(ctx, c)
if err != nil { if err != nil {
return err return err

View File

@ -35,18 +35,18 @@ func Before(ctx context.Context, c *cli.Command) (context.Context, error) {
waitForUpdateCheck, cancelWaitForUpdate = context.WithCancelCause(context.Background()) waitForUpdateCheck, cancelWaitForUpdate = context.WithCancelCause(context.Background())
defer cancelWaitForUpdate(errors.New("update check finished")) defer cancelWaitForUpdate(errors.New("update check finished"))
log.Debug().Msg("Checking for updates ...") log.Debug().Msg("checking for updates ...")
newVersion, err := update.CheckForUpdate(waitForUpdateCheck, false) //nolint:contextcheck newVersion, err := update.CheckForUpdate(waitForUpdateCheck, false) //nolint:contextcheck
if err != nil { if err != nil {
log.Error().Err(err).Msgf("Failed to check for updates") log.Error().Err(err).Msgf("failed to check for updates")
return return
} }
if newVersion != nil { if newVersion != nil {
log.Warn().Msgf("A new version of woodpecker-cli is available: %s. Update by running: %s update", newVersion.Version, c.Root().Name) log.Warn().Msgf("new version of woodpecker-cli is available: %s, update with: %s update", newVersion.Version, c.Root().Name)
} else { } else {
log.Debug().Msgf("No update required") log.Debug().Msgf("no update required")
} }
}(ctx) }(ctx)
@ -59,7 +59,7 @@ func After(_ context.Context, _ *cli.Command) error {
case <-waitForUpdateCheck.Done(): case <-waitForUpdateCheck.Done():
// When the actual command already finished, we still wait 500ms for the update check to finish // When the actual command already finished, we still wait 500ms for the update check to finish
case <-time.After(time.Millisecond * 500): case <-time.After(time.Millisecond * 500):
log.Debug().Msg("Update check stopped due to timeout") log.Debug().Msg("update check stopped due to timeout")
cancelWaitForUpdate(errors.New("update check timeout")) cancelWaitForUpdate(errors.New("update check timeout"))
} }
} }

View File

@ -44,7 +44,7 @@ func Load(ctx context.Context, c *cli.Command) error {
} }
if config.ServerURL == "" || config.Token == "" { if config.ServerURL == "" || config.Token == "" {
log.Info().Msg("The woodpecker-cli is not yet set up. Please run `woodpecker-cli setup` or provide the required environment variables / flags.") log.Info().Msg("woodpecker-cli is not set up, run `woodpecker-cli setup` or provide required environment variables/flags")
return errors.New("woodpecker-cli is not configured") return errors.New("woodpecker-cli is not configured")
} }
@ -63,7 +63,7 @@ func Load(ctx context.Context, c *cli.Command) error {
return err return err
} }
log.Debug().Any("config", config).Msg("Loaded config") log.Debug().Any("config", config).Msg("loaded config")
return nil return nil
} }
@ -93,16 +93,16 @@ func Get(_ context.Context, c *cli.Command, _configPath string) (*Config, error)
return nil, err return nil, err
} }
log.Debug().Str("configPath", configPath).Msg("Checking for config file") log.Debug().Str("configPath", configPath).Msg("checking for config file")
content, err := os.ReadFile(configPath) content, err := os.ReadFile(configPath)
switch { switch {
case err != nil && !os.IsNotExist(err): case err != nil && !os.IsNotExist(err):
log.Debug().Err(err).Msg("Failed to read the config file") log.Debug().Err(err).Msg("failed to read the config file")
return nil, err return nil, err
case err != nil && os.IsNotExist(err): case err != nil && os.IsNotExist(err):
log.Debug().Msg("The config file does not exist") log.Debug().Msg("config file does not exist")
default: default:
configFromFile := &Config{} configFromFile := &Config{}
@ -111,7 +111,7 @@ func Get(_ context.Context, c *cli.Command, _configPath string) (*Config, error)
return nil, err return nil, err
} }
conf.MergeIfNotSet(configFromFile) conf.MergeIfNotSet(configFromFile)
log.Debug().Msg("Loaded config from file") log.Debug().Msg("loaded config from file")
} }
// if server or token are explicitly set, use them // if server or token are explicitly set, use them
@ -123,11 +123,11 @@ func Get(_ context.Context, c *cli.Command, _configPath string) (*Config, error)
service := c.Root().Name service := c.Root().Name
secret, err := keyring.Get(service, conf.ServerURL) secret, err := keyring.Get(service, conf.ServerURL)
if errors.Is(err, keyring.ErrUnsupportedPlatform) { if errors.Is(err, keyring.ErrUnsupportedPlatform) {
log.Warn().Msg("Keyring is not supported on this platform") log.Warn().Msg("keyring is not supported on this platform")
return conf, nil return conf, nil
} }
if errors.Is(err, keyring.ErrNotFound) { if errors.Is(err, keyring.ErrNotFound) {
log.Warn().Msg("Token not found in keyring") log.Warn().Msg("token not found in keyring")
return conf, nil return conf, nil
} }
conf.Token = secret conf.Token = secret

View File

@ -40,12 +40,12 @@ var Command = &cli.Command{
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Sources: cli.EnvVars("WOODPECKER_PLUGINS_PRIVILEGED"), Sources: cli.EnvVars("WOODPECKER_PLUGINS_PRIVILEGED"),
Name: "plugins-privileged", Name: "plugins-privileged",
Usage: "Allow plugins to run in privileged mode, if environment variable is defined but empty there will be none", Usage: "allow plugins to run in privileged mode, if set empty, there is no",
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Sources: cli.EnvVars("WOODPECKER_PLUGINS_TRUSTED_CLONE"), Sources: cli.EnvVars("WOODPECKER_PLUGINS_TRUSTED_CLONE"),
Name: "plugins-trusted-clone", Name: "plugins-trusted-clone",
Usage: "Plugins which are trusted to handle Git credentials in clone steps", Usage: "plugins that are trusted to handle Git credentials in cloning steps",
Value: constant.TrustedClonePlugins, Value: constant.TrustedClonePlugins,
}, },
&cli.BoolFlag{ &cli.BoolFlag{

View File

@ -30,7 +30,7 @@ var Command = &cli.Command{
registryCreateCmd, registryCreateCmd,
registryDeleteCmd, registryDeleteCmd,
registryUpdateCmd, registryUpdateCmd,
registryInfoCmd, registryShowCmd,
registryListCmd, registryListCmd,
}, },
} }

View File

@ -28,7 +28,7 @@ import (
var registryCreateCmd = &cli.Command{ var registryCreateCmd = &cli.Command{
Name: "add", Name: "add",
Usage: "adds a registry", Usage: "add a registry",
ArgsUsage: "[org-id|org-full-name]", ArgsUsage: "[org-id|org-full-name]",
Action: registryCreate, Action: registryCreate,
Flags: []cli.Flag{ Flags: []cli.Flag{

View File

@ -25,11 +25,11 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal" "go.woodpecker-ci.org/woodpecker/v2/cli/internal"
) )
var registryInfoCmd = &cli.Command{ var registryShowCmd = &cli.Command{
Name: "info", Name: "show",
Usage: "display registry info", Usage: "show registry information",
ArgsUsage: "[org-id|org-full-name]", ArgsUsage: "[org-id|org-full-name]",
Action: registryInfo, Action: registryShow,
Flags: []cli.Flag{ Flags: []cli.Flag{
common.OrgFlag, common.OrgFlag,
&cli.StringFlag{ &cli.StringFlag{
@ -41,7 +41,7 @@ var registryInfoCmd = &cli.Command{
}, },
} }
func registryInfo(ctx context.Context, c *cli.Command) error { func registryShow(ctx context.Context, c *cli.Command) error {
var ( var (
hostname = c.String("hostname") hostname = c.String("hostname")
format = c.String("format") + "\n" format = c.String("format") + "\n"

View File

@ -30,7 +30,7 @@ var Command = &cli.Command{
secretCreateCmd, secretCreateCmd,
secretDeleteCmd, secretDeleteCmd,
secretUpdateCmd, secretUpdateCmd,
secretInfoCmd, secretShowCmd,
secretListCmd, secretListCmd,
}, },
} }

View File

@ -28,7 +28,7 @@ import (
var secretCreateCmd = &cli.Command{ var secretCreateCmd = &cli.Command{
Name: "add", Name: "add",
Usage: "adds a secret", Usage: "add a secret",
ArgsUsage: "[repo-id|repo-full-name]", ArgsUsage: "[repo-id|repo-full-name]",
Action: secretCreate, Action: secretCreate,
Flags: []cli.Flag{ Flags: []cli.Flag{

View File

@ -43,11 +43,11 @@ var secretUpdateCmd = &cli.Command{
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "event", Name: "event",
Usage: "secret limited to these events", Usage: "limit secret to these event",
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "image", Name: "image",
Usage: "secret limited to these images", Usage: "limit secret to these image",
}, },
}, },
} }

View File

@ -26,11 +26,11 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal" "go.woodpecker-ci.org/woodpecker/v2/cli/internal"
) )
var secretInfoCmd = &cli.Command{ var secretShowCmd = &cli.Command{
Name: "info", Name: "show",
Usage: "display secret info", Usage: "show secret information",
ArgsUsage: "[repo-id|repo-full-name]", ArgsUsage: "[repo-id|repo-full-name]",
Action: secretInfo, Action: secretShow,
Flags: []cli.Flag{ Flags: []cli.Flag{
common.OrgFlag, common.OrgFlag,
&cli.StringFlag{ &cli.StringFlag{
@ -41,7 +41,7 @@ var secretInfoCmd = &cli.Command{
}, },
} }
func secretInfo(ctx context.Context, c *cli.Command) error { func secretShow(ctx context.Context, c *cli.Command) error {
var ( var (
secretName = c.String("name") secretName = c.String("name")
format = c.String("format") + "\n" format = c.String("format") + "\n"

View File

@ -53,7 +53,7 @@ var Command = &cli.Command{
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "param", Name: "param",
Aliases: []string{"p"}, Aliases: []string{"p"},
Usage: "custom parameters to be injected into the step environment. Format: KEY=value", Usage: "custom parameters to inject into the step environment. Format: KEY=value",
}, },
}, },
} }

View File

@ -26,7 +26,7 @@ import (
var pipelineLastCmd = &cli.Command{ var pipelineLastCmd = &cli.Command{
Name: "last", Name: "last",
Usage: "show latest pipeline details", Usage: "show latest pipeline information",
ArgsUsage: "<repo-id|repo-full-name>", ArgsUsage: "<repo-id|repo-full-name>",
Action: pipelineLast, Action: pipelineLast,
Flags: append(common.OutputFlags("table"), []cli.Flag{ Flags: append(common.OutputFlags("table"), []cli.Flag{

View File

@ -52,7 +52,7 @@ func buildPipelineListCmd() *cli.Command {
}, },
&cli.TimestampFlag{ &cli.TimestampFlag{
Name: "before", Name: "before",
Usage: "only return pipelines before this RFC3339 date", Usage: "only return pipelines before this date (RFC3339)",
Config: cli.TimestampConfig{ Config: cli.TimestampConfig{
Layouts: []string{ Layouts: []string{
time.RFC3339, time.RFC3339,
@ -61,7 +61,7 @@ func buildPipelineListCmd() *cli.Command {
}, },
&cli.TimestampFlag{ &cli.TimestampFlag{
Name: "after", Name: "after",
Usage: "only return pipelines after this RFC3339 date", Usage: "only return pipelines after this date (RFC3339)",
Config: cli.TimestampConfig{ Config: cli.TimestampConfig{
Layouts: []string{ Layouts: []string{
time.RFC3339, time.RFC3339,

View File

@ -35,7 +35,7 @@ var Command = &cli.Command{
Commands: []*cli.Command{ Commands: []*cli.Command{
buildPipelineListCmd(), buildPipelineListCmd(),
pipelineLastCmd, pipelineLastCmd,
pipelineInfoCmd, pipelineShowCmd,
pipelineStopCmd, pipelineStopCmd,
pipelineStartCmd, pipelineStartCmd,
pipelineApproveCmd, pipelineApproveCmd,

View File

@ -25,15 +25,15 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker" "go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker"
) )
var pipelineInfoCmd = &cli.Command{ var pipelineShowCmd = &cli.Command{
Name: "info", Name: "show",
Usage: "show pipeline details", Usage: "show pipeline information",
ArgsUsage: "<repo-id|repo-full-name> [pipeline]", ArgsUsage: "<repo-id|repo-full-name> [pipeline]",
Action: pipelineInfo, Action: pipelineShow,
Flags: common.OutputFlags("table"), Flags: common.OutputFlags("table"),
} }
func pipelineInfo(ctx context.Context, c *cli.Command) error { func pipelineShow(ctx context.Context, c *cli.Command) error {
repoIDOrFullName := c.Args().First() repoIDOrFullName := c.Args().First()
client, err := internal.NewClient(ctx, c) client, err := internal.NewClient(ctx, c)
if err != nil { if err != nil {

View File

@ -35,7 +35,7 @@ var pipelineStartCmd = &cli.Command{
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "param", Name: "param",
Aliases: []string{"p"}, Aliases: []string{"p"},
Usage: "custom parameters to be injected into the step environment. Format: KEY=value", Usage: "custom parameters to inject into the step environment. Format: KEY=value",
}, },
}, },
} }

View File

@ -26,7 +26,7 @@ var Command = &cli.Command{
cronCreateCmd, cronCreateCmd,
cronDeleteCmd, cronDeleteCmd,
cronUpdateCmd, cronUpdateCmd,
cronInfoCmd, cronShowCmd,
cronListCmd, cronListCmd,
}, },
} }

View File

@ -25,11 +25,11 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal" "go.woodpecker-ci.org/woodpecker/v2/cli/internal"
) )
var cronInfoCmd = &cli.Command{ var cronShowCmd = &cli.Command{
Name: "info", Name: "show",
Usage: "display info about a cron job", Usage: "show cron job information",
ArgsUsage: "[repo-id|repo-full-name]", ArgsUsage: "[repo-id|repo-full-name]",
Action: cronInfo, Action: cronShow,
Flags: []cli.Flag{ Flags: []cli.Flag{
common.RepoFlag, common.RepoFlag,
&cli.StringFlag{ &cli.StringFlag{
@ -41,7 +41,7 @@ var cronInfoCmd = &cli.Command{
}, },
} }
func cronInfo(ctx context.Context, c *cli.Command) error { func cronShow(ctx context.Context, c *cli.Command) error {
var ( var (
cronID = c.Int("id") cronID = c.Int("id")
repoIDOrFullName = c.String("repository") repoIDOrFullName = c.String("repository")

View File

@ -29,7 +29,7 @@ var Command = &cli.Command{
registryCreateCmd, registryCreateCmd,
registryDeleteCmd, registryDeleteCmd,
registryUpdateCmd, registryUpdateCmd,
registryInfoCmd, registryShowCmd,
registryListCmd, registryListCmd,
}, },
} }

View File

@ -28,7 +28,7 @@ import (
var registryCreateCmd = &cli.Command{ var registryCreateCmd = &cli.Command{
Name: "add", Name: "add",
Usage: "adds a registry", Usage: "add a registry",
ArgsUsage: "[repo-id|repo-full-name]", ArgsUsage: "[repo-id|repo-full-name]",
Action: registryCreate, Action: registryCreate,
Flags: []cli.Flag{ Flags: []cli.Flag{

View File

@ -25,11 +25,11 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal" "go.woodpecker-ci.org/woodpecker/v2/cli/internal"
) )
var registryInfoCmd = &cli.Command{ var registryShowCmd = &cli.Command{
Name: "info", Name: "show",
Usage: "display registry info", Usage: "show registry information",
ArgsUsage: "[repo-id|repo-full-name]", ArgsUsage: "[repo-id|repo-full-name]",
Action: registryInfo, Action: registryShow,
Flags: []cli.Flag{ Flags: []cli.Flag{
common.RepoFlag, common.RepoFlag,
&cli.StringFlag{ &cli.StringFlag{
@ -41,7 +41,7 @@ var registryInfoCmd = &cli.Command{
}, },
} }
func registryInfo(ctx context.Context, c *cli.Command) error { func registryShow(ctx context.Context, c *cli.Command) error {
var ( var (
hostname = c.String("hostname") hostname = c.String("hostname")
format = c.String("format") + "\n" format = c.String("format") + "\n"

View File

@ -28,7 +28,7 @@ var Command = &cli.Command{
Usage: "manage repositories", Usage: "manage repositories",
Commands: []*cli.Command{ Commands: []*cli.Command{
repoListCmd, repoListCmd,
repoInfoCmd, repoShowCmd,
repoAddCmd, repoAddCmd,
repoUpdateCmd, repoUpdateCmd,
repoRemoveCmd, repoRemoveCmd,

View File

@ -25,15 +25,15 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal" "go.woodpecker-ci.org/woodpecker/v2/cli/internal"
) )
var repoInfoCmd = &cli.Command{ var repoShowCmd = &cli.Command{
Name: "info", Name: "show",
Usage: "show repository details", Usage: "show repository information",
ArgsUsage: "<repo-id|repo-full-name>", ArgsUsage: "<repo-id|repo-full-name>",
Action: repoInfo, Action: repoShow,
Flags: []cli.Flag{common.FormatFlag(tmplRepoInfo)}, Flags: []cli.Flag{common.FormatFlag(tmplRepoInfo)},
} }
func repoInfo(ctx context.Context, c *cli.Command) error { func repoShow(ctx context.Context, c *cli.Command) error {
repoIDOrFullName := c.Args().First() repoIDOrFullName := c.Args().First()
client, err := internal.NewClient(ctx, c) client, err := internal.NewClient(ctx, c)
if err != nil { if err != nil {

View File

@ -53,7 +53,7 @@ var repoUpdateCmd = &cli.Command{
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "config", Name: "config",
Usage: "repository configuration path (e.g. .woodpecker.yml)", Usage: "repository configuration path. Example: .woodpecker.yml",
}, },
&cli.IntFlag{ &cli.IntFlag{
Name: "pipeline-counter", Name: "pipeline-counter",
@ -61,7 +61,7 @@ var repoUpdateCmd = &cli.Command{
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "unsafe", Name: "unsafe",
Usage: "validate updating the pipeline-counter is unsafe", Usage: "allow unsafe operations",
}, },
}, },
} }

View File

@ -29,7 +29,7 @@ var Command = &cli.Command{
secretCreateCmd, secretCreateCmd,
secretDeleteCmd, secretDeleteCmd,
secretUpdateCmd, secretUpdateCmd,
secretInfoCmd, secretShowCmd,
secretListCmd, secretListCmd,
}, },
} }

View File

@ -28,7 +28,7 @@ import (
var secretCreateCmd = &cli.Command{ var secretCreateCmd = &cli.Command{
Name: "add", Name: "add",
Usage: "adds a secret", Usage: "add a secret",
ArgsUsage: "[repo-id|repo-full-name]", ArgsUsage: "[repo-id|repo-full-name]",
Action: secretCreate, Action: secretCreate,
Flags: []cli.Flag{ Flags: []cli.Flag{
@ -43,11 +43,11 @@ var secretCreateCmd = &cli.Command{
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "event", Name: "event",
Usage: "secret limited to these events", Usage: "limit secret to these events",
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "image", Name: "image",
Usage: "secret limited to these images", Usage: "limit secret to these images",
}, },
}, },
} }

View File

@ -43,11 +43,11 @@ var secretUpdateCmd = &cli.Command{
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "event", Name: "event",
Usage: "secret limited to these events", Usage: "limit secret to these events",
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "image", Name: "image",
Usage: "secret limited to these images", Usage: "limit secret to these images",
}, },
}, },
} }

View File

@ -26,11 +26,11 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal" "go.woodpecker-ci.org/woodpecker/v2/cli/internal"
) )
var secretInfoCmd = &cli.Command{ var secretShowCmd = &cli.Command{
Name: "info", Name: "show",
Usage: "display secret info", Usage: "show secret information",
ArgsUsage: "[repo-id|repo-full-name]", ArgsUsage: "[repo-id|repo-full-name]",
Action: secretInfo, Action: secretShow,
Flags: []cli.Flag{ Flags: []cli.Flag{
common.RepoFlag, common.RepoFlag,
&cli.StringFlag{ &cli.StringFlag{
@ -41,7 +41,7 @@ var secretInfoCmd = &cli.Command{
}, },
} }
func secretInfo(ctx context.Context, c *cli.Command) error { func secretShow(ctx context.Context, c *cli.Command) error {
var ( var (
secretName = c.String("name") secretName = c.String("name")
format = c.String("format") + "\n" format = c.String("format") + "\n"

View File

@ -20,11 +20,11 @@ var Command = &cli.Command{
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "server", Name: "server",
Usage: "The URL of the woodpecker server", Usage: "URL of the woodpecker server",
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "token", Name: "token",
Usage: "The token to authenticate with the woodpecker server", Usage: "token to authenticate with the woodpecker server",
}, },
}, },
Action: setup, Action: setup,
@ -41,7 +41,7 @@ func setup(ctx context.Context, c *cli.Command) error {
} }
if !setupAgain { if !setupAgain {
log.Info().Msg("Configuration skipped") log.Info().Msg("configuration skipped")
return nil return nil
} }
} }
@ -87,7 +87,7 @@ func setup(ctx context.Context, c *cli.Command) error {
return err return err
} }
log.Info().Msg("The woodpecker-cli has been successfully setup") log.Info().Msg("woodpecker-cli has been successfully setup")
return nil return nil
} }

View File

@ -24,12 +24,12 @@ func receiveTokenFromUI(c context.Context, serverURL string) (string, error) {
srv.Handler = setupRouter(tokenReceived) srv.Handler = setupRouter(tokenReceived)
go func() { go func() {
log.Debug().Msgf("Listening for token response on :%d", port) log.Debug().Msgf("listening for token response on :%d", port)
_ = srv.ListenAndServe() _ = srv.ListenAndServe()
}() }()
defer func() { defer func() {
log.Debug().Msg("Shutting down server") log.Debug().Msg("shutting down server")
_ = srv.Shutdown(c) _ = srv.Shutdown(c)
}() }()
@ -90,7 +90,7 @@ func setupRouter(tokenReceived chan string) *gin.Engine {
err := c.BindJSON(&data) err := c.BindJSON(&data)
if err != nil { if err != nil {
log.Debug().Err(err).Msg("Failed to bind JSON") log.Debug().Err(err).Msg("failed to bind JSON")
c.JSON(http.StatusBadRequest, gin.H{ c.JSON(http.StatusBadRequest, gin.H{
"error": "invalid request", "error": "invalid request",
}) })
@ -110,7 +110,7 @@ func setupRouter(tokenReceived chan string) *gin.Engine {
func openBrowser(url string) error { func openBrowser(url string) error {
var err error var err error
log.Debug().Msgf("Opening browser with URL: %s", url) log.Debug().Msgf("opening browser with URL: %s", url)
switch runtime.GOOS { switch runtime.GOOS {
case "linux": case "linux":

View File

@ -24,7 +24,7 @@ var Command = &cli.Command{
} }
func update(ctx context.Context, c *cli.Command) error { func update(ctx context.Context, c *cli.Command) error {
log.Info().Msg("Checking for updates ...") log.Info().Msg("checking for updates ...")
newVersion, err := CheckForUpdate(ctx, c.Bool("force")) newVersion, err := CheckForUpdate(ctx, c.Bool("force"))
if err != nil { if err != nil {
@ -32,11 +32,11 @@ func update(ctx context.Context, c *cli.Command) error {
} }
if newVersion == nil { if newVersion == nil {
fmt.Println("You are using the latest version of woodpecker-cli") fmt.Println("you are using the latest version of woodpecker-cli")
return nil return nil
} }
log.Info().Msgf("New version %s is available! Updating ...", newVersion.Version) log.Info().Msgf("new version %s is available! Updating ...", newVersion.Version)
var tarFilePath string var tarFilePath string
tarFilePath, err = downloadNewVersion(ctx, newVersion.AssetURL) tarFilePath, err = downloadNewVersion(ctx, newVersion.AssetURL)
@ -44,14 +44,14 @@ func update(ctx context.Context, c *cli.Command) error {
return err return err
} }
log.Debug().Msgf("New version %s has been downloaded successfully! Installing ...", newVersion.Version) log.Debug().Msgf("new version %s has been downloaded successfully! Installing ...", newVersion.Version)
binFile, err := extractNewVersion(tarFilePath) binFile, err := extractNewVersion(tarFilePath)
if err != nil { if err != nil {
return err return err
} }
log.Debug().Msgf("New version %s has been extracted to %s", newVersion.Version, binFile) log.Debug().Msgf("new version %s has been extracted to %s", newVersion.Version, binFile)
executablePathOrSymlink, err := os.Executable() executablePathOrSymlink, err := os.Executable()
if err != nil { if err != nil {

View File

@ -22,10 +22,10 @@ func CheckForUpdate(ctx context.Context, force bool) (*NewVersion, error) {
} }
func checkForUpdate(ctx context.Context, versionURL string, force bool) (*NewVersion, error) { func checkForUpdate(ctx context.Context, versionURL string, force bool) (*NewVersion, error) {
log.Debug().Msgf("Current version: %s", version.String()) log.Debug().Msgf("current version: %s", version.String())
if (version.String() == "dev" || strings.HasPrefix(version.String(), "next-")) && !force { if (version.String() == "dev" || strings.HasPrefix(version.String(), "next-")) && !force {
log.Debug().Msgf("Skipping update check for development & next versions") log.Debug().Msgf("skipping update check for development/next versions")
return nil, nil return nil, nil
} }
@ -61,11 +61,11 @@ func checkForUpdate(ctx context.Context, versionURL string, force bool) (*NewVer
// using the latest release // using the latest release
if installedVersion == upstreamVersion && !force { if installedVersion == upstreamVersion && !force {
log.Debug().Msgf("No new version available") log.Debug().Msgf("no new version available")
return nil, nil return nil, nil
} }
log.Debug().Msgf("New version available: %s", upstreamVersion) log.Debug().Msgf("new version available: %s", upstreamVersion)
assetURL := fmt.Sprintf(githubBinaryURL, upstreamVersion, runtime.GOOS, runtime.GOARCH) assetURL := fmt.Sprintf(githubBinaryURL, upstreamVersion, runtime.GOOS, runtime.GOARCH)
return &NewVersion{ return &NewVersion{
@ -75,7 +75,7 @@ func checkForUpdate(ctx context.Context, versionURL string, force bool) (*NewVer
} }
func downloadNewVersion(ctx context.Context, downloadURL string) (string, error) { func downloadNewVersion(ctx context.Context, downloadURL string) (string, error) {
log.Debug().Msgf("Downloading new version from %s ...", downloadURL) log.Debug().Msgf("downloading new version from %s ...", downloadURL)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadURL, nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadURL, nil)
if err != nil { if err != nil {
@ -102,13 +102,13 @@ func downloadNewVersion(ctx context.Context, downloadURL string) (string, error)
return "", err return "", err
} }
log.Debug().Msgf("New version downloaded to %s", file.Name()) log.Debug().Msgf("new version downloaded to %s", file.Name())
return file.Name(), nil return file.Name(), nil
} }
func extractNewVersion(tarFilePath string) (string, error) { func extractNewVersion(tarFilePath string) (string, error) {
log.Debug().Msgf("Extracting new version from %s ...", tarFilePath) log.Debug().Msgf("extracting new version from %s ...", tarFilePath)
tarFile, err := os.Open(tarFilePath) tarFile, err := os.Open(tarFilePath)
if err != nil { if err != nil {
@ -132,7 +132,7 @@ func extractNewVersion(tarFilePath string) (string, error) {
return "", err return "", err
} }
log.Debug().Msgf("New version extracted to %s", tmpDir) log.Debug().Msgf("new version extracted to %s", tmpDir)
return path.Join(tmpDir, "woodpecker-cli"), nil return path.Join(tmpDir, "woodpecker-cli"), nil
} }

View File

@ -43,6 +43,7 @@ This will be the next version of Woodpecker.
- `woodpecker-cli cron` is now `woodpecker-cli repo cron` - `woodpecker-cli cron` is now `woodpecker-cli repo cron`
- `woodpecker-cli secret [add|rm|...] --repository` is now `woodpecker-cli repo secret [add|rm|...]` - `woodpecker-cli secret [add|rm|...] --repository` is now `woodpecker-cli repo secret [add|rm|...]`
- `woodpecker-cli pipeline logs` is now `woodpecker-cli pipeline log show` - `woodpecker-cli pipeline logs` is now `woodpecker-cli pipeline log show`
- `woodpecker-cli [registry|secret|...] info` is now `woodpecker-cli [registry|secret|...] show`
## Admin migrations ## Admin migrations