mirror of
https://github.com/goreleaser/nfpm
synced 2024-11-18 23:14:12 +01:00
8b1af19c32
* feat: add flag argument completions * feat: do not offer completions for commands taking no args
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
_ "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/rpm" // rpm packager
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func Execute(version string, 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 string, exit func(int)) *rootCmd {
|
|
root := &rootCmd{
|
|
exit: exit,
|
|
}
|
|
cmd := &cobra.Command{
|
|
Use: "nfpm",
|
|
Short: "Packages apps on RPM, Deb and APK formats based on a YAML configuration file",
|
|
Long: `nFPM is a simple, 0-dependencies, deb, rpm and apk packager.`,
|
|
Version: version,
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
Args: cobra.NoArgs,
|
|
ValidArgsFunction: cobra.NoFileCompletions,
|
|
}
|
|
|
|
cmd.AddCommand(
|
|
newInitCmd().cmd,
|
|
newPackageCmd().cmd,
|
|
newDocsCmd().cmd,
|
|
newManCmd().cmd,
|
|
newSchemaCmd().cmd,
|
|
)
|
|
|
|
root.cmd = cmd
|
|
return root
|
|
}
|