github.com/goreleaser/nfpm/v2@v2.44.0/internal/cmd/init.go (about) 1 package cmd 2 3 import ( 4 _ "embed" 5 "fmt" 6 "os" 7 8 "github.com/spf13/cobra" 9 ) 10 11 //go:embed example.yml 12 var example []byte 13 14 type initCmd struct { 15 cmd *cobra.Command 16 config string 17 } 18 19 func newInitCmd() *initCmd { 20 root := &initCmd{} 21 cmd := &cobra.Command{ 22 Use: "init", 23 Aliases: []string{"i"}, 24 Short: "Creates a sample nfpm.yaml configuration file", 25 SilenceUsage: true, 26 SilenceErrors: true, 27 Args: cobra.NoArgs, 28 ValidArgsFunction: cobra.NoFileCompletions, 29 RunE: func(_ *cobra.Command, _ []string) error { 30 if err := os.WriteFile(root.config, example, 0o666); err != nil { 31 return fmt.Errorf("failed to create example file: %w", err) 32 } 33 return nil 34 }, 35 } 36 37 cmd.Flags().StringVarP(&root.config, "config", "f", "nfpm.yaml", "path to the to-be-created config file") 38 _ = cmd.MarkFlagFilename("config", "yaml", "yml") 39 40 root.cmd = cmd 41 return root 42 }