Files
nfpm/internal/cmd/root.go
Dj GilcreaseandClaude Fable 5.2 410234f7ef feat(macos): add app, dmg and pkg packagers
Three packagers for macOS, built in pure Go on any platform:

- pkg: an installer package (.pkg) from contents and the preinstall and
  postinstall scripts, as a product archive that declares its
  architecture.
- app: an application bundle delivered as a zip (.app.zip), with a
  generated Info.plist.
- dmg: the same bundle in a disk image (.dmg) next to a link to the
  Applications folder.

app and dmg share the new "app" settings; pkg has its own. All three
take name, version, arch and contents from the shared fields, can be
signed with a PKCS#12 identity, and report the shared settings macOS has
no place for instead of dropping them silently.

Refs #535, #536.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-20 11:35:17 -08:00

70 lines
1.9 KiB
Go

package cmd
import (
"context"
"os"
goversion "github.com/caarlos0/go-version"
"github.com/charmbracelet/fang"
_ "github.com/goreleaser/nfpm/v2/apk" // apk packager
_ "github.com/goreleaser/nfpm/v2/app" // macOS app packager
_ "github.com/goreleaser/nfpm/v2/arch" // archlinux packager
_ "github.com/goreleaser/nfpm/v2/deb" // deb packager
_ "github.com/goreleaser/nfpm/v2/dmg" // macOS dmg packager
_ "github.com/goreleaser/nfpm/v2/ipk" // ipk packager
_ "github.com/goreleaser/nfpm/v2/msi" // msi packager
_ "github.com/goreleaser/nfpm/v2/msix" // msix packager
_ "github.com/goreleaser/nfpm/v2/pkg" // macOS pkg packager
_ "github.com/goreleaser/nfpm/v2/rpm" // rpm packager
"github.com/spf13/cobra"
)
func Execute(version goversion.Info, exit func(int), args []string) {
newRootCmd(version, exit).Execute(args)
}
type rootCmd struct {
cmd *cobra.Command
exit func(int)
}
func (cmd *rootCmd) Execute(args []string) {
cmd.cmd.SetArgs(args)
if err := fang.Execute(
context.Background(),
cmd.cmd,
fang.WithVersion(cmd.cmd.Version),
fang.WithColorSchemeFunc(fang.AnsiColorScheme),
fang.WithNotifySignal(os.Interrupt, os.Kill),
fang.WithoutVersion(),
); err != nil {
cmd.exit(1)
}
}
func newRootCmd(version goversion.Info, exit func(int)) *rootCmd {
root := &rootCmd{
exit: exit,
}
cmd := &cobra.Command{
Use: "nfpm",
Short: "Packages apps on RPM, Deb, APK, Arch Linux, ipk, MSI, MSIX, and macOS (app, dmg, pkg) formats based on a YAML configuration file",
Long: `nFPM is a simple and 0-dependencies apk, app, arch, deb, dmg, ipk, msi, msix, pkg, and rpm packager written in Go.`,
Version: version.String(),
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
}
cmd.SetVersionTemplate("{{.Version}}")
cmd.AddCommand(
newInitCmd().cmd,
newPackageCmd().cmd,
newDocsCmd().cmd,
newSchemaCmd().cmd,
)
root.cmd = cmd
return root
}