change send cmd to invoke (#211)

This commit is contained in:
Yaron Schneider 2019-11-20 16:22:41 -08:00 committed by GitHub
parent 5fc4924080
commit eeea3d5a1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 55 deletions

View File

@ -230,7 +230,7 @@ $ dapr run --app-id nodeapp --app-port 3000 node app.js
Invoke your app:
```
$ dapr send --app-id nodeapp --method mymethod
$ dapr invoke --app-id nodeapp --method mymethod
```
### List

46
cmd/invoke.go Normal file
View File

@ -0,0 +1,46 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------
package cmd
import (
"fmt"
"os"
"github.com/dapr/cli/pkg/invoke"
"github.com/dapr/cli/pkg/print"
"github.com/spf13/cobra"
)
var invokeAppID string
var invokeAppMethod string
var invokePayload string
var InvokeCmd = &cobra.Command{
Use: "invoke",
Short: "invoke a dapr app with an optional payload",
Run: func(cmd *cobra.Command, args []string) {
response, err := invoke.InvokeApp(invokeAppID, invokeAppMethod, invokePayload)
if err != nil {
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error invoking app %s: %s", invokeAppID, err))
return
}
if response != "" {
fmt.Println(response)
}
print.SuccessStatusEvent(os.Stdout, "App invoked successfully")
},
}
func init() {
InvokeCmd.Flags().StringVarP(&invokeAppID, "app-id", "a", "", "the app id to invoke")
InvokeCmd.Flags().StringVarP(&invokeAppMethod, "method", "m", "", "the method to invoke")
InvokeCmd.Flags().StringVarP(&invokePayload, "payload", "p", "", "(optional) a json payload")
InvokeCmd.MarkFlagRequired("app-id")
InvokeCmd.MarkFlagRequired("method")
RootCmd.AddCommand(InvokeCmd)
}

View File

@ -1,46 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------
package cmd
import (
"fmt"
"os"
"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/pkg/send"
"github.com/spf13/cobra"
)
var sendAppID string
var sendAppMethod string
var sendPayload string
var SendCmd = &cobra.Command{
Use: "send",
Short: "invoke a dapr app with an optional payload",
Run: func(cmd *cobra.Command, args []string) {
response, err := send.InvokeApp(sendAppID, sendAppMethod, sendPayload)
if err != nil {
print.FailureStatusEvent(os.Stdout, fmt.Sprintf("Error invoking app %s: %s", sendAppID, err))
return
}
if response != "" {
fmt.Println(response)
}
print.SuccessStatusEvent(os.Stdout, "App invoked successfully")
},
}
func init() {
SendCmd.Flags().StringVarP(&sendAppID, "app-id", "a", "", "the app id to invoke")
SendCmd.Flags().StringVarP(&sendAppMethod, "method", "m", "", "the method to invoke")
SendCmd.Flags().StringVarP(&sendPayload, "payload", "p", "", "(optional) a json payload")
SendCmd.MarkFlagRequired("app-id")
SendCmd.MarkFlagRequired("method")
RootCmd.AddCommand(SendCmd)
}

View File

@ -1,4 +1,4 @@
# dapr send
# dapr invoke
## Description
@ -7,7 +7,7 @@ Invoke a Dapr app with an optional payload
## Usage
```bash
dapr send [flags]
dapr invoke [flags]
```
## Flags
@ -15,6 +15,6 @@ dapr send [flags]
| Name | Environment Variable | Default | Description
| --- | --- | --- | --- |
| `--app-id`, `-a` | | | The app ID to invoke |
| `--help`, `-h` | | | Help for send |
| `--help`, `-h` | | | Help for invoke |
| `--method`, `-m` | | | The method to invoke |
| `--payload`, `-p` | | | A JSON payload |

View File

@ -20,11 +20,11 @@ Available Commands:
help Help about any command
init Setup dapr in Kubernetes or Standalone modes
list List all dapr instances
publish publish an event to multiple consumers
publish Publish an event to multiple consumers
run Launches dapr and your app side by side
send invoke a dapr app with an optional payload
invoke Invoke a dapr app with an optional payload
stop Stops a running dapr instance and its associated app
uninstall removes a dapr installation
uninstall Removes a dapr installation
Flags:
-h, --help help for dapr
@ -42,7 +42,7 @@ You can learn more about each Dapr command from the links below.
- [`dapr list`](dapr-list.md)
- [`dapr publish`](dapr-publish.md)
- [`dapr run`](dapr-run.md)
- [`dapr send`](dapr-send.md)
- [`dapr invoke`](dapr-invoke.md)
- [`dapr stop`](dapr-stop.md)
- [`dapr uninstall`](dapr-uninstall.md)

View File

@ -3,7 +3,7 @@
// Licensed under the MIT License.
// ------------------------------------------------------------
package send
package invoke
import (
"bytes"