mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
|
"github.com/apex/log"
|
||
|
"github.com/fatih/color"
|
||
|
"github.com/goreleaser/goreleaser/internal/static"
|
||
|
"github.com/spf13/cobra"
|
||
|
)
|
||
|
|
||
|
type initCmd struct {
|
||
|
cmd *cobra.Command
|
||
|
config string
|
||
|
}
|
||
|
|
||
|
func newInitCmd() *initCmd {
|
||
|
var root = &initCmd{}
|
||
|
var cmd = &cobra.Command{
|
||
|
Use: "init",
|
||
|
Aliases: []string{"i"},
|
||
|
Short: "Generates a .goreleaser.yml file",
|
||
|
SilenceUsage: true,
|
||
|
SilenceErrors: true,
|
||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||
|
f, err := os.OpenFile(root.config, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_EXCL, 0644)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer f.Close()
|
||
|
|
||
|
log.Infof(color.New(color.Bold).Sprintf("Generating %s file", root.config))
|
||
|
if _, err := f.WriteString(static.ExampleConfig); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
log.WithField("file", root.config).Info("config created; please edit accordingly to your needs")
|
||
|
return nil
|
||
|
},
|
||
|
}
|
||
|
|
||
|
cmd.Flags().StringVarP(&root.config, "config", "f", ".goreleaser.yml", "Load configuration from file")
|
||
|
|
||
|
root.cmd = cmd
|
||
|
return root
|
||
|
}
|