Skip to content

Commit

Permalink
feat: init from example
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Feb 16, 2018
1 parent e5fe548 commit 186cf62
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 25 deletions.
14 changes: 13 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions cmd/nfpm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/alecthomas/kingpin"
"github.com/gobuffalo/packr"
"github.com/goreleaser/nfpm"
_ "github.com/goreleaser/nfpm/deb"
_ "github.com/goreleaser/nfpm/rpm"
Expand All @@ -29,7 +30,7 @@ func main() {
if err := initFile(*config); err != nil {
kingpin.Fatalf(err.Error())
}
fmt.Printf("created empty config file at %s, edit at will\n", *config)
fmt.Printf("created config file from example: %s\n", *config)
case pkgCmd.FullCommand():
if err := doPackage(*config, *format, *target); err != nil {
kingpin.Fatalf(err.Error())
Expand All @@ -38,11 +39,8 @@ func main() {
}

func initFile(config string) error {
yml, err := yaml.Marshal(nfpm.Info{})
if err != nil {
return err
}
return ioutil.WriteFile(config, yml, 0666)
box := packr.NewBox("./nfpm.yaml.example")
return ioutil.WriteFile(config, box.Bytes("."), 0666)
}

func doPackage(config, format, target string) error {
Expand Down
29 changes: 29 additions & 0 deletions cmd/nfpm/nfpm.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "foo"
arch: "amd64"
platform: "linux"
version: "1.0.0"
section: "default"
priority: "extra"
replaces:
- foobar
provides:
- bar
depends:
- foo
- bar
conflicts:
- not-foo
- not-bar
maintainer: "John Doe <john@example.com>"
description: |
FooBar is the great foo and bar software.
And this can be in multiple lines!
vendor: "FooBarCorp"
homepage: "http://eaxmple.com"
license: "MIT"
bindir: "/usr/local/bin"
files:
./foo: "/usr/local/bin/foo"
./bar: "/usr/local/bin/bar"
config_files:
./foobar.conf: "/etc/foobar.conf"
36 changes: 18 additions & 18 deletions nfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ type Packager interface {

// Info contains information about the package
type Info struct {
Name string `yaml:"name"`
Arch string `yaml:"arch"`
Platform string `yaml:"platform"`
Version string `yaml:"version"`
Section string `yaml:"section"`
Priority string `yaml:"priority"`
Replaces []string `yaml:"replaces"`
Provides []string `yaml:"provides"`
Depends []string `yaml:"depends"`
Conflicts []string `yaml:"conflicts"`
Maintainer string `yaml:"maintainer"`
Description string `yaml:"description"`
Vendor string `yaml:"vendor"`
Homepage string `yaml:"homepage"`
License string `yaml:"license"`
Bindir string `yaml:"bindir"`
Files map[string]string `yaml:"files"`
ConfigFiles map[string]string `yaml:"config_files"`
Name string `yaml:"name,omitempty"`
Arch string `yaml:"arch,omitempty"`
Platform string `yaml:"platform,omitempty"`
Version string `yaml:"version,omitempty"`
Section string `yaml:"section,omitempty"`
Priority string `yaml:"priority,omitempty"`
Replaces []string `yaml:"replaces,omitempty"`
Provides []string `yaml:"provides,omitempty"`
Depends []string `yaml:"depends,omitempty"`
Conflicts []string `yaml:"conflicts,omitempty"`
Maintainer string `yaml:"maintainer,omitempty"`
Description string `yaml:"description,omitempty"`
Vendor string `yaml:"vendor,omitempty"`
Homepage string `yaml:"homepage,omitempty"`
License string `yaml:"license,omitempty"`
Bindir string `yaml:"bindir,omitempty"`
Files map[string]string `yaml:"files,omitempty"`
ConfigFiles map[string]string `yaml:"config_files,omitempty"`
}

// WithDefaults set some sane defaults into the given Info
Expand Down

0 comments on commit 186cf62

Please sign in to comment.