Skip to content

Commit

Permalink
Unify cli commands and flags
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys committed Nov 29, 2024
1 parent 359e3af commit 32068f2
Show file tree
Hide file tree
Showing 41 changed files with 112 additions and 93 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
2 changes: 1 addition & 1 deletion cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func execWithAxis(ctx context.Context, c *cli.Command, file, repoPath string, ax
pipelineEnv[before] = after
if oldVar, exists := environ[before]; exists {
// override existing values, but print a warning
log.Warn().Msgf("environment variable '%s' had value '%s', but got overwritten", before, oldVar)
log.Warn().Msgf("Environment variable '%s' had value '%s', but got overwritten", before, oldVar)
}
environ[before] = after
}
Expand Down
12 changes: 6 additions & 6 deletions cli/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewClient(ctx context.Context, c *cli.Command) (woodpecker.Client, error) {
// attempt to find system CA certs
certs, err := x509.SystemCertPool()
if err != nil {
log.Error().Err(err).Msg("failed to find system CA certs")
log.Error().Err(err).Msg("Failed to find system CA certs")
}
tlsConfig := &tls.Config{
RootCAs: certs,
Expand Down Expand Up @@ -101,7 +101,7 @@ func getRepoFromGit(remoteName string) (string, error) {

gitRemote := strings.TrimSpace(string(stdout))

log.Debug().Str("git-remote", gitRemote).Msg("extracted remote url from git")
log.Debug().Str("git-remote", gitRemote).Msg("Extracted remote url from git")

if len(gitRemote) == 0 {
return "", fmt.Errorf("no repository provided")
Expand All @@ -113,7 +113,7 @@ func getRepoFromGit(remoteName string) (string, error) {
}

repoFullName := u.FullName
log.Debug().Str("repo", repoFullName).Msg("extracted repository from remote url")
log.Debug().Str("repo", repoFullName).Msg("Extracted repository from remote url")

return repoFullName, nil
}
Expand All @@ -123,19 +123,19 @@ func ParseRepo(client woodpecker.Client, str string) (repoID int64, err error) {
if str == "" {
str, err = getRepoFromGit("upstream")
if err != nil {
log.Debug().Err(err).Msg("could not get repository from git upstream remote")
log.Debug().Err(err).Msg("Could not get repository from git upstream remote")
}
}

if str == "" {
str, err = getRepoFromGit("origin")
if err != nil {
log.Debug().Err(err).Msg("could not get repository from git origin remote")
log.Debug().Err(err).Msg("Could not get repository from git origin remote")
}
}

if str == "" {
return 0, fmt.Errorf("no repository provided")
return 0, fmt.Errorf("no repoSsitory provided")
}

if strings.Contains(str, "/") {
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 @@ -36,7 +36,7 @@ var Command = &cli.Command{
buildPipelineListCmd(),
pipelineLastCmd,
pipelineLogsCmd,
pipelineInfoCmd,
pipelineShowCmd,
pipelineStopCmd,
pipelineStartCmd,
pipelineApproveCmd,
Expand Down
10 changes: 5 additions & 5 deletions cli/pipeline/info.go → cli/pipeline/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker"
)

var pipelineInfoCmd = &cli.Command{
Name: "info",
Usage: "show pipeline details",
var pipelineShowCmd = &cli.Command{
Name: "show",
Usage: "show pipeline information",
ArgsUsage: "<repo-id|repo-full-name> [pipeline]",
Action: pipelineInfo,
Action: pipelineShow,
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()
client, err := internal.NewClient(ctx, c)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cli/pipeline/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var pipelineStartCmd = &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/repo/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var Command = &cli.Command{
cronCreateCmd,
cronDeleteCmd,
cronUpdateCmd,
cronInfoCmd,
cronShowCmd,
cronListCmd,
},
}
Loading

0 comments on commit 32068f2

Please sign in to comment.