mirror of
https://github.com/snapp-incubator/pakhshi.git
synced 2025-09-26 20:21:13 +08:00
35 lines
910 B
Go
35 lines
910 B
Go
package cmd
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/pterm/pterm"
|
|
"github.com/snapp-incubator/pakhshi/example/cli/internal/cmd/publish"
|
|
"github.com/snapp-incubator/pakhshi/example/cli/internal/cmd/subscribe"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// ExitFailure status code.
|
|
const ExitFailure = 1
|
|
|
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
|
func Execute() {
|
|
// nolint: exhaustivestruct
|
|
root := &cobra.Command{
|
|
Use: "pakhshi",
|
|
}
|
|
|
|
brokers := new([]string)
|
|
root.PersistentFlags().StringSliceVarP(brokers, "brokers", "b",
|
|
[]string{"tcp://127.0.0.1:1883"}, "brokers e.g. tcp://127.0.0.1:1883")
|
|
|
|
subscribe.Register(root, brokers)
|
|
publish.Register(root, brokers)
|
|
|
|
if err := root.Execute(); err != nil {
|
|
pterm.Error.Printf("failed to execute root command: %s", err.Error())
|
|
os.Exit(ExitFailure)
|
|
}
|
|
}
|