Skip to content

Commit

Permalink
feat: replace cobra with coral (#2881)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Feb 4, 2022
1 parent 114c3a8 commit a5d3e7b
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 134 deletions.
10 changes: 5 additions & 5 deletions cmd/build.go
Expand Up @@ -15,11 +15,11 @@ import (
"github.com/goreleaser/goreleaser/internal/pipeline"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/spf13/cobra"
"github.com/muesli/coral"
)

type buildCmd struct {
cmd *cobra.Command
cmd *coral.Command
opts buildOpts
}

Expand All @@ -39,7 +39,7 @@ type buildOpts struct {
func newBuildCmd() *buildCmd {
root := &buildCmd{}
// nolint: dupl
cmd := &cobra.Command{
cmd := &coral.Command{
Use: "build",
Aliases: []string{"b"},
Short: "Builds the current project",
Expand All @@ -60,8 +60,8 @@ defaulting to the current's machine target if not set.
`,
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
start := time.Now()

log.Infof(color.New(color.Bold).Sprint("building..."))
Expand Down
10 changes: 5 additions & 5 deletions cmd/check.go
Expand Up @@ -10,26 +10,26 @@ import (
"github.com/fatih/color"
"github.com/goreleaser/goreleaser/internal/pipe/defaults"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/spf13/cobra"
"github.com/muesli/coral"
)

type checkCmd struct {
cmd *cobra.Command
cmd *coral.Command
config string
quiet bool
deprecated bool
}

func newCheckCmd() *checkCmd {
root := &checkCmd{}
cmd := &cobra.Command{
cmd := &coral.Command{
Use: "check",
Aliases: []string{"c"},
Short: "Checks if configuration is valid",
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
if root.quiet {
log.SetHandler(cli.New(io.Discard))
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/docs.go
Expand Up @@ -3,24 +3,24 @@ package cmd
import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"github.com/muesli/coral"
"github.com/muesli/coral/doc"
)

type docsCmd struct {
cmd *cobra.Command
cmd *coral.Command
}

func newDocsCmd() *docsCmd {
root := &docsCmd{}
cmd := &cobra.Command{
cmd := &coral.Command{
Use: "docs",
Short: "Generates GoReleaser's command line docs",
SilenceUsage: true,
DisableFlagsInUseLine: true,
Hidden: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
root.cmd.Root().DisableAutoGenTag = true
return doc.GenMarkdownTreeCustom(root.cmd.Root(), "www/docs/cmd", func(_ string) string {
return ""
Expand Down
10 changes: 5 additions & 5 deletions cmd/init.go
Expand Up @@ -6,24 +6,24 @@ import (
"github.com/apex/log"
"github.com/fatih/color"
"github.com/goreleaser/goreleaser/internal/static"
"github.com/spf13/cobra"
"github.com/muesli/coral"
)

type initCmd struct {
cmd *cobra.Command
cmd *coral.Command
config string
}

func newInitCmd() *initCmd {
root := &initCmd{}
cmd := &cobra.Command{
cmd := &coral.Command{
Use: "init",
Aliases: []string{"i"},
Short: "Generates a .goreleaser.yaml file",
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
conf, err := os.OpenFile(root.config, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_EXCL, 0o644)
if err != nil {
return err
Expand Down
14 changes: 7 additions & 7 deletions cmd/man.go
Expand Up @@ -4,26 +4,26 @@ import (
"fmt"
"os"

mcobra "github.com/muesli/mango-cobra"
"github.com/muesli/coral"
mcoral "github.com/muesli/mango-coral"
"github.com/muesli/roff"
"github.com/spf13/cobra"
)

type manCmd struct {
cmd *cobra.Command
cmd *coral.Command
}

func newManCmd() *manCmd {
root := &manCmd{}
cmd := &cobra.Command{
cmd := &coral.Command{
Use: "man",
Short: "Generates GoReleaser's command line manpages",
SilenceUsage: true,
DisableFlagsInUseLine: true,
Hidden: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
manPage, err := mcobra.NewManPageFromCobra(1, root.cmd.Root())
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
manPage, err := mcoral.NewManPage(1, root.cmd.Root())
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/release.go
Expand Up @@ -13,11 +13,11 @@ import (
"github.com/goreleaser/goreleaser/internal/pipe/git"
"github.com/goreleaser/goreleaser/internal/pipeline"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/spf13/cobra"
"github.com/muesli/coral"
)

type releaseCmd struct {
cmd *cobra.Command
cmd *coral.Command
opts releaseOpts
}

Expand Down Expand Up @@ -45,14 +45,14 @@ type releaseOpts struct {
func newReleaseCmd() *releaseCmd {
root := &releaseCmd{}
// nolint: dupl
cmd := &cobra.Command{
cmd := &coral.Command{
Use: "release",
Aliases: []string{"r"},
Short: "Releases the current project",
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
start := time.Now()

log.Infof(color.New(color.Bold).Sprint("releasing..."))
Expand Down
14 changes: 7 additions & 7 deletions cmd/root.go
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/apex/log"
"github.com/apex/log/handlers/cli"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/muesli/coral"
)

func Execute(version string, exit func(int), args []string) {
Expand Down Expand Up @@ -42,7 +42,7 @@ func (cmd *rootCmd) Execute(args []string) {
}

type rootCmd struct {
cmd *cobra.Command
cmd *coral.Command
debug bool
exit func(int)
}
Expand All @@ -51,7 +51,7 @@ func newRootCmd(version string, exit func(int)) *rootCmd {
root := &rootCmd{
exit: exit,
}
cmd := &cobra.Command{
cmd := &coral.Command{
Use: "goreleaser",
Short: "Deliver Go binaries as fast and easily as possible",
Long: `GoReleaser is a release automation tool for Go projects.
Expand All @@ -67,8 +67,8 @@ single .goreleaser.yaml file.
Version: version,
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
Args: coral.NoArgs,
PersistentPreRun: func(cmd *coral.Command, args []string) {
if root.debug {
log.SetLevel(log.DebugLevel)
log.Debug("debug logs enabled")
Expand All @@ -91,7 +91,7 @@ single .goreleaser.yaml file.
return root
}

func shouldPrependRelease(cmd *cobra.Command, args []string) bool {
func shouldPrependRelease(cmd *coral.Command, args []string) bool {
// find current cmd, if its not root, it means the user actively
// set a command, so let it go
xmd, _, _ := cmd.Find(args)
Expand All @@ -101,7 +101,7 @@ func shouldPrependRelease(cmd *cobra.Command, args []string) bool {

// allow help and the two __complete commands.
if len(args) > 0 && (args[0] == "help" || args[0] == "completion" ||
args[0] == cobra.ShellCompRequestCmd || args[0] == cobra.ShellCompNoDescRequestCmd) {
args[0] == coral.ShellCompRequestCmd || args[0] == coral.ShellCompNoDescRequestCmd) {
return false
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/schema.go
Expand Up @@ -8,24 +8,24 @@ import (

"github.com/alecthomas/jsonschema"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/spf13/cobra"
"github.com/muesli/coral"
)

type schemaCmd struct {
cmd *cobra.Command
cmd *coral.Command
output string
}

func newSchemaCmd() *schemaCmd {
root := &schemaCmd{}
cmd := &cobra.Command{
cmd := &coral.Command{
Use: "jsonschema",
Aliases: []string{"schema"},
Short: "outputs goreleaser's JSON schema",
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Args: coral.NoArgs,
RunE: func(cmd *coral.Command, args []string) error {
schema := jsonschema.Reflect(&config.Project{})
schema.Description = "goreleaser configuration definition file"
bts, err := json.MarshalIndent(schema, " ", " ")
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Expand Up @@ -25,10 +25,10 @@ require (
github.com/imdario/mergo v0.3.12
github.com/jarcoal/httpmock v1.1.0
github.com/mitchellh/go-homedir v1.1.0
github.com/muesli/mango-cobra v0.0.0-20220201011537-57e8ea90d84d
github.com/muesli/coral v1.0.0
github.com/muesli/mango-coral v1.0.1
github.com/muesli/roff v0.1.0
github.com/slack-go/slack v0.10.1
github.com/spf13/cobra v1.3.0
github.com/stretchr/testify v1.7.0
github.com/ulikunitz/xz v0.5.10
github.com/xanzy/go-gitlab v0.54.4
Expand Down Expand Up @@ -108,6 +108,7 @@ require (
github.com/goreleaser/chglog v0.1.2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.0.0 // indirect
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
github.com/hashicorp/go-version v1.3.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
Expand Down

0 comments on commit a5d3e7b

Please sign in to comment.