Skip to content

Commit

Permalink
Unify cli commands and flags (#4481)
Browse files Browse the repository at this point in the history
- Unify command and flag descriptions
- Unify logs
- Rename `woodpecker-cli [registry|ssecret|...] info` commands to `woodpecker-cli [registry|ssecret|...] show`
  • Loading branch information
xoxys authored Nov 30, 2024
1 parent 9a8d7d8 commit 57e7572
Show file tree
Hide file tree
Showing 43 changed files with 119 additions and 118 deletions.
4 changes: 2 additions & 2 deletions cli/admin/loglevel/loglevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
var Command = &cli.Command{
Name: "log-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,
}

Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion cli/admin/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var Command = &cli.Command{
registryCreateCmd,
registryDeleteCmd,
registryUpdateCmd,
registryInfoCmd,
registryShowCmd,
registryListCmd,
},
}
2 changes: 1 addition & 1 deletion cli/admin/registry/registry_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

var registryCreateCmd = &cli.Command{
Name: "add",
Usage: "adds a registry",
Usage: "add a registry",
Action: registryCreate,
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
)

var registryInfoCmd = &cli.Command{
Name: "info",
Usage: "display registry info",
Action: registryInfo,
var registryShowCmd = &cli.Command{
Name: "show",
Usage: "show registry information",
Action: registryShow,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "hostname",
Expand All @@ -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 (
hostname = c.String("hostname")
format = c.String("format") + "\n"
Expand Down
2 changes: 1 addition & 1 deletion cli/admin/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var Command = &cli.Command{
secretCreateCmd,
secretDeleteCmd,
secretUpdateCmd,
secretInfoCmd,
secretShowCmd,
secretListCmd,
},
}
2 changes: 1 addition & 1 deletion cli/admin/secret/secret_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

var secretCreateCmd = &cli.Command{
Name: "add",
Usage: "adds a secret",
Usage: "add a secret",
ArgsUsage: "[repo-id|repo-full-name]",
Action: secretCreate,
Flags: []cli.Flag{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
)

var secretInfoCmd = &cli.Command{
Name: "info",
Usage: "display secret info",
var secretShowCmd = &cli.Command{
Name: "show",
Usage: "show secret information",
ArgsUsage: "[repo-id|repo-full-name]",
Action: secretInfo,
Action: secretShow,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Expand All @@ -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 (
secretName = c.String("name")
format = c.String("format") + "\n"
Expand Down
2 changes: 1 addition & 1 deletion cli/admin/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var Command = &cli.Command{
Usage: "manage users",
Commands: []*cli.Command{
userListCmd,
userInfoCmd,
userShowCmd,
userAddCmd,
userRemoveCmd,
},
Expand Down
2 changes: 1 addition & 1 deletion cli/admin/user/user_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

var userAddCmd = &cli.Command{
Name: "add",
Usage: "adds a user",
Usage: "add a user",
ArgsUsage: "<username>",
Action: userAdd,
}
Expand Down
10 changes: 5 additions & 5 deletions cli/admin/user/user_info.go → cli/admin/user/user_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
)

var userInfoCmd = &cli.Command{
Name: "info",
Usage: "show user details",
var userShowCmd = &cli.Command{
Name: "show",
Usage: "show user information",
ArgsUsage: "<username>",
Action: userInfo,
Action: userShow,
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)
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions cli/common/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ func Before(ctx context.Context, c *cli.Command) (context.Context, error) {
waitForUpdateCheck, cancelWaitForUpdate = context.WithCancelCause(context.Background())
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
if err != nil {
log.Error().Err(err).Msgf("Failed to check for updates")
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.Root().Name)
log.Warn().Msgf("new version of woodpecker-cli is available: %s, update with: %s update", newVersion.Version, c.Root().Name)
} else {
log.Debug().Msgf("No update required")
log.Debug().Msgf("no update required")
}
}(ctx)

Expand All @@ -59,7 +59,7 @@ func After(_ context.Context, _ *cli.Command) error {
case <-waitForUpdateCheck.Done():
// When the actual command already finished, we still wait 500ms for the update check to finish
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"))
}
}
Expand Down
16 changes: 8 additions & 8 deletions cli/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func Load(ctx context.Context, c *cli.Command) error {
}

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")
}

Expand All @@ -63,7 +63,7 @@ func Load(ctx context.Context, c *cli.Command) error {
return err
}

log.Debug().Any("config", config).Msg("Loaded config")
log.Debug().Any("config", config).Msg("loaded config")

return nil
}
Expand Down Expand Up @@ -93,16 +93,16 @@ func Get(_ context.Context, c *cli.Command, _configPath string) (*Config, error)
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)
switch {
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

case err != nil && os.IsNotExist(err):
log.Debug().Msg("The config file does not exist")
log.Debug().Msg("config file does not exist")

default:
configFromFile := &Config{}
Expand All @@ -111,7 +111,7 @@ func Get(_ context.Context, c *cli.Command, _configPath string) (*Config, error)
return nil, err
}
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
Expand All @@ -123,11 +123,11 @@ func Get(_ context.Context, c *cli.Command, _configPath string) (*Config, error)
service := c.Root().Name
secret, err := keyring.Get(service, conf.ServerURL)
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
}
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
}
conf.Token = secret
Expand Down
4 changes: 2 additions & 2 deletions cli/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ var Command = &cli.Command{
&cli.StringSliceFlag{
Sources: cli.EnvVars("WOODPECKER_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{
Sources: cli.EnvVars("WOODPECKER_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,
},
&cli.BoolFlag{
Expand Down
2 changes: 1 addition & 1 deletion cli/org/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var Command = &cli.Command{
registryCreateCmd,
registryDeleteCmd,
registryUpdateCmd,
registryInfoCmd,
registryShowCmd,
registryListCmd,
},
}
Expand Down
2 changes: 1 addition & 1 deletion cli/org/registry/registry_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

var registryCreateCmd = &cli.Command{
Name: "add",
Usage: "adds a registry",
Usage: "add a registry",
ArgsUsage: "[org-id|org-full-name]",
Action: registryCreate,
Flags: []cli.Flag{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
)

var registryInfoCmd = &cli.Command{
Name: "info",
Usage: "display registry info",
var registryShowCmd = &cli.Command{
Name: "show",
Usage: "show registry information",
ArgsUsage: "[org-id|org-full-name]",
Action: registryInfo,
Action: registryShow,
Flags: []cli.Flag{
common.OrgFlag,
&cli.StringFlag{
Expand All @@ -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 (
hostname = c.String("hostname")
format = c.String("format") + "\n"
Expand Down
2 changes: 1 addition & 1 deletion cli/org/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var Command = &cli.Command{
secretCreateCmd,
secretDeleteCmd,
secretUpdateCmd,
secretInfoCmd,
secretShowCmd,
secretListCmd,
},
}
Expand Down
2 changes: 1 addition & 1 deletion cli/org/secret/secret_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

var secretCreateCmd = &cli.Command{
Name: "add",
Usage: "adds a secret",
Usage: "add a secret",
ArgsUsage: "[repo-id|repo-full-name]",
Action: secretCreate,
Flags: []cli.Flag{
Expand Down
4 changes: 2 additions & 2 deletions cli/org/secret/secret_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ var secretUpdateCmd = &cli.Command{
},
&cli.StringSliceFlag{
Name: "event",
Usage: "secret limited to these events",
Usage: "limit secret to these event",
},
&cli.StringSliceFlag{
Name: "image",
Usage: "secret limited to these images",
Usage: "limit secret to these image",
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions cli/org/secret/secret_info.go → cli/org/secret/secret_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/cli/internal"
)

var secretInfoCmd = &cli.Command{
Name: "info",
Usage: "display secret info",
var secretShowCmd = &cli.Command{
Name: "show",
Usage: "show secret information",
ArgsUsage: "[repo-id|repo-full-name]",
Action: secretInfo,
Action: secretShow,
Flags: []cli.Flag{
common.OrgFlag,
&cli.StringFlag{
Expand All @@ -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 (
secretName = c.String("name")
format = c.String("format") + "\n"
Expand Down
2 changes: 1 addition & 1 deletion cli/pipeline/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var Command = &cli.Command{
&cli.StringSliceFlag{
Name: "param",
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",
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion cli/pipeline/last.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

var pipelineLastCmd = &cli.Command{
Name: "last",
Usage: "show latest pipeline details",
Usage: "show latest pipeline information",
ArgsUsage: "<repo-id|repo-full-name>",
Action: pipelineLast,
Flags: append(common.OutputFlags("table"), []cli.Flag{
Expand Down
4 changes: 2 additions & 2 deletions cli/pipeline/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func buildPipelineListCmd() *cli.Command {
},
&cli.TimestampFlag{
Name: "before",
Usage: "only return pipelines before this RFC3339 date",
Usage: "only return pipelines before this date (RFC3339)",
Config: cli.TimestampConfig{
Layouts: []string{
time.RFC3339,
Expand All @@ -61,7 +61,7 @@ func buildPipelineListCmd() *cli.Command {
},
&cli.TimestampFlag{
Name: "after",
Usage: "only return pipelines after this RFC3339 date",
Usage: "only return pipelines after this date (RFC3339)",
Config: cli.TimestampConfig{
Layouts: []string{
time.RFC3339,
Expand Down
2 changes: 1 addition & 1 deletion cli/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var Command = &cli.Command{
Commands: []*cli.Command{
buildPipelineListCmd(),
pipelineLastCmd,
pipelineInfoCmd,
pipelineShowCmd,
pipelineStopCmd,
pipelineStartCmd,
pipelineApproveCmd,
Expand Down
Loading

0 comments on commit 57e7572

Please sign in to comment.