mirror of https://github.com/dapr/cli.git
remove redundant app-id from publish cmd (#43)
This commit is contained in:
parent
9e40ecb0bd
commit
2f7e11b286
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var publishAppID string
|
||||
var publishTopic string
|
||||
var publishPayload string
|
||||
|
||||
|
|
@ -17,7 +16,7 @@ var PublishCmd = &cobra.Command{
|
|||
Use: "publish",
|
||||
Short: "publish an event to multiple consumers",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
err := publish.PublishTopic(publishAppID, publishTopic, publishPayload)
|
||||
err := publish.PublishTopic(publishTopic, publishPayload)
|
||||
if err != nil {
|
||||
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error publishing topic %s: %s", publishTopic, err))
|
||||
return
|
||||
|
|
@ -29,7 +28,6 @@ var PublishCmd = &cobra.Command{
|
|||
|
||||
func init() {
|
||||
PublishCmd.Flags().StringVarP(&publishTopic, "topic", "t", "", "the topic the app is listening on")
|
||||
PublishCmd.Flags().StringVarP(&publishAppID, "app-id", "a", "", "The app to publish the message to")
|
||||
PublishCmd.Flags().StringVarP(&publishPayload, "payload", "p", "", "(optional) a json payload")
|
||||
PublishCmd.MarkFlagRequired("app-id")
|
||||
PublishCmd.MarkFlagRequired("topic")
|
||||
|
|
|
|||
|
|
@ -10,11 +10,9 @@ import (
|
|||
"github.com/actionscore/cli/pkg/standalone"
|
||||
)
|
||||
|
||||
func PublishTopic(appID, topic, payload string) error {
|
||||
func PublishTopic(topic, payload string) error {
|
||||
if topic == "" {
|
||||
return errors.New("topic is missing")
|
||||
} else if appID == "" {
|
||||
return errors.New("app id is missing")
|
||||
}
|
||||
|
||||
l, err := standalone.List()
|
||||
|
|
@ -22,23 +20,22 @@ func PublishTopic(appID, topic, payload string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
for _, lo := range l {
|
||||
if lo.AppID == appID {
|
||||
b := []byte{}
|
||||
|
||||
if payload != "" {
|
||||
b = []byte(payload)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("http://localhost:%s/v%s/publish/%s", fmt.Sprintf("%v", lo.ActionsPort), api.RuntimeAPIVersion, topic)
|
||||
_, err = http.Post(url, "application/json", bytes.NewBuffer(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
if len(l) == 0 {
|
||||
return errors.New("couldn't find a running Actions instance")
|
||||
}
|
||||
|
||||
return fmt.Errorf("App id %s not found", appID)
|
||||
app := l[0]
|
||||
b := []byte{}
|
||||
|
||||
if payload != "" {
|
||||
b = []byte(payload)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("http://localhost:%s/v%s/publish/%s", fmt.Sprintf("%v", app.ActionsPort), api.RuntimeAPIVersion, topic)
|
||||
_, err = http.Post(url, "application/json", bytes.NewBuffer(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue