mirror of
https://github.com/snapp-incubator/pakhshi.git
synced 2025-10-06 16:47:05 +08:00
feat: move example to its package
This commit is contained in:
34
example/cli/internal/cmd/root.go
Normal file
34
example/cli/internal/cmd/root.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user