forked from goreleaser/nfpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
59 lines (50 loc) · 1.46 KB
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cmd
import (
"fmt"
goversion "github.com/caarlos0/go-version"
_ "github.com/goreleaser/nfpm/v2/apk" // apk packager
_ "github.com/goreleaser/nfpm/v2/arch" // archlinux packager
_ "github.com/goreleaser/nfpm/v2/deb" // deb packager
_ "github.com/goreleaser/nfpm/v2/ipk" // ipk 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 := cmd.cmd.Execute(); err != nil {
fmt.Println(err.Error())
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, and ipk formats based on a YAML configuration file",
Long: `nFPM is a simple and 0-dependencies apk, arch, deb, ipk and rpm linux packager written in Go.`,
Version: version.String(),
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
}
cmd.SetVersionTemplate("{{.Version}}")
cmd.AddCommand(
newInitCmd().cmd,
newPackageCmd().cmd,
newDocsCmd().cmd,
newManCmd().cmd,
newSchemaCmd().cmd,
)
root.cmd = cmd
return root
}