blasphem/internal/common/common.go
2022-11-20 08:49:24 -05:00

41 lines
733 B
Go

// common contains common functionality for blasphem.
package common
import (
"github.com/spf13/cobra"
)
const (
// AppName is the name of the application.
AppName = "blasphem"
)
type cmdOptions interface {
Options(*cobra.Command, []string) error
Execute() error
}
func AppNamePtr() *string {
s := AppName
return &s
}
func IntPtr(i int) *int { return &i }
// RunE is a convenience function for use with cobra.
func RunE(c cmdOptions) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
err := c.Options(cmd, args)
if err != nil {
cmd.SilenceUsage = true
return err
}
err = c.Execute()
if err != nil {
cmd.SilenceUsage = true
}
return err
}
}