1
1
mirror of https://github.com/goreleaser/nfpm synced 2024-11-18 23:14:12 +01:00
nfpm/internal/cmd/init.go
Carlos Alexandro Becker dcf239f316
feat(deps): switch back to cobra (#506)
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
2022-05-07 23:28:43 -03:00

91 lines
1.7 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
type initCmd struct {
cmd *cobra.Command
config string
}
func newInitCmd() *initCmd {
root := &initCmd{}
cmd := &cobra.Command{
Use: "init",
Aliases: []string{"i"},
Short: "Creates a sample nfpm.yaml config file",
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if err := os.WriteFile(root.config, []byte(example), 0o666); err != nil {
return fmt.Errorf("failed to create example file: %w", err)
}
return nil
},
}
cmd.Flags().StringVarP(&root.config, "config", "f", "nfpm.yaml", "path to the to-be-created config file")
root.cmd = cmd
return root
}
const example = `# nfpm example config file
#
# check https://nfpm.goreleaser.com/configuration for detailed usage
#
name: "foo"
arch: "amd64"
platform: "linux"
version: "v1.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/local/bin/foo
- src: ./bar
dst: /usr/local/bin/bar
- src: ./foobar.conf
dst: /etc/foobar.conf
type: config
- src: /usr/local/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
`