blasphem/internal/common/common.go

35 lines
638 B
Go
Raw Permalink Normal View History

2022-11-13 11:55:10 -05:00
// common contains common functionality for blasphem.
2022-09-25 11:42:36 -04:00
package common
import (
"github.com/spf13/cobra"
)
const (
2022-11-13 11:55:10 -05:00
// AppName is the name of the application.
2022-09-25 11:42:36 -04:00
AppName = "blasphem"
)
type cmdOptions interface {
Options(*cobra.Command, []string) error
Execute() error
}
2022-11-13 11:55:10 -05:00
// RunE is a convenience function for use with cobra.
2022-09-25 11:42:36 -04:00
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
}
}