1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-03 13:11:48 +02:00

Draft of the init command

This commit is contained in:
lucapette 2017-04-27 11:03:26 +02:00
parent f243c931b2
commit b287048fe1
4 changed files with 61 additions and 0 deletions

View File

@ -104,3 +104,16 @@ func Load(file string) (config Project, err error) {
err = yaml.Unmarshal(data, &config)
return
}
// DefaultConfig returns a default configuration for the init command
func DefaultConfig() string {
return `
build:
binary: drum-roll
goos:
- windows
- darwin
- linux
goarch:
- amd64`
}

16
config/config_test.go Normal file
View File

@ -0,0 +1,16 @@
package config
import (
"testing"
yaml "gopkg.in/yaml.v1"
)
func TestDefaultConfig(t *testing.T) {
cfg := DefaultConfig()
config := Project{}
if err := yaml.Unmarshal([]byte(cfg), &config); err != nil {
t.Errorf("Not a valid config. %s", err.Error())
}
}

View File

@ -5,6 +5,8 @@ import (
"log"
"os"
"fmt"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline"
@ -77,3 +79,17 @@ func Release(flags Flags) error {
log.Println("Done!")
return nil
}
// InitProject creates an example goreleaser.yml in the current directory
func InitProject() error {
filename := "goreleaser.yml"
if _, err := os.Stat(filename); !os.IsNotExist(err) {
if err != nil {
return err
}
return fmt.Errorf("%s already exists", filename)
}
return ioutil.WriteFile(filename, []byte(config.DefaultConfig()), 0644)
}

16
main.go
View File

@ -46,6 +46,22 @@ func main() {
}
return nil
}
app.Commands = []cli.Command{
{
Name: "init",
Aliases: []string{"i"},
Usage: "generate goreleaser.yml",
Action: func(c *cli.Context) error {
err := goreleaserlib.InitProject()
if err != nil {
return err
}
log.Printf("goreleaser.yml created. Please edit accordingly to your needs.")
return nil
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatalln(err)
}