Skip to content

Commit

Permalink
fix: improve init
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Oct 25, 2024
1 parent b207f76 commit 9aef48e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 56 deletions.
56 changes: 56 additions & 0 deletions internal/cmd/example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This is an example nfpm configuration file.
# Make sure to check the documentation at https://nfpm.goreleaser.com
#
# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://nfpm.goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

name: "foo"
arch: "amd64"
platform: "linux"
version: "1.0.0"
section: "default"
priority: "extra"
replaces:
- foobar
provides:
- bar
depends:
- foo
- bar
recommends:
- whatever
suggests:
- something-else
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://example.com"
license: "MIT"
changelog: "changelog.yaml"
contents:
- src: ./foo
dst: /usr/bin/foo
- src: ./bar
dst: /usr/bin/bar
- src: ./foobar.conf
dst: /etc/foobar.conf
type: config
- src: /usr/bin/foo
dst: /sbin/foo
type: symlink
overrides:
rpm:
scripts:
preinstall: ./scripts/preinstall.sh
postremove: ./scripts/postremove.sh
deb:
scripts:
postinstall: ./scripts/postinstall.sh
preremove: ./scripts/preremove.sh
60 changes: 5 additions & 55 deletions internal/cmd/init.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package cmd

import (
_ "embed"
"fmt"
"os"

"github.com/spf13/cobra"
)

//go:embed example.yml
var example []byte

type initCmd struct {
cmd *cobra.Command
config string
Expand All @@ -23,7 +27,7 @@ func newInitCmd() *initCmd {
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(_ *cobra.Command, _ []string) error {
if err := os.WriteFile(root.config, []byte(example), 0o666); err != nil {
if err := os.WriteFile(root.config, example, 0o666); err != nil {
return fmt.Errorf("failed to create example file: %w", err)
}
return nil
Expand All @@ -36,57 +40,3 @@ func newInitCmd() *initCmd {
root.cmd = cmd
return root
}

const example = `# nfpm example configuration file
#
# check https://nfpm.goreleaser.com/configuration for detailed usage
#
name: "foo"
arch: "amd64"
platform: "linux"
version: "1.0.0"
section: "default"
priority: "extra"
replaces:
- foobar
provides:
- bar
depends:
- foo
- bar
recommends:
- whatever
suggests:
- something-else
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://example.com"
license: "MIT"
changelog: "changelog.yaml"
contents:
- src: ./foo
dst: /usr/bin/foo
- src: ./bar
dst: /usr/bin/bar
- src: ./foobar.conf
dst: /etc/foobar.conf
type: config
- src: /usr/bin/foo
dst: /sbin/foo
type: symlink
overrides:
rpm:
scripts:
preinstall: ./scripts/preinstall.sh
postremove: ./scripts/postremove.sh
deb:
scripts:
postinstall: ./scripts/postinstall.sh
preremove: ./scripts/preremove.sh
`
2 changes: 1 addition & 1 deletion www/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ So I decided to create nFPM: a **simpler**, **0-dependency**,
This is a subtle way of saying it won't have all features, nor all
formats that `fpm` has: it is supposed to be simpler.

And that's OK!, most of us don't need all those features most of the time.
And that's OK! Most of us don't need all those features most of the time.

[fpm]: https://github.com/jordansissel/fpm

Expand Down

0 comments on commit 9aef48e

Please sign in to comment.