From eeea3d5a1b9042974731294c5d10d4829706f01b Mon Sep 17 00:00:00 2001 From: Yaron Schneider Date: Wed, 20 Nov 2019 16:22:41 -0800 Subject: [PATCH] change send cmd to invoke (#211) --- README.md | 2 +- cmd/invoke.go | 46 +++++++++++++++++++ cmd/send.go | 46 ------------------- .../{dapr-send.md => dapr-invoke.md} | 6 +-- docs/reference/reference.md | 8 ++-- pkg/{send/send.go => invoke/invoke.go} | 2 +- 6 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 cmd/invoke.go delete mode 100644 cmd/send.go rename docs/reference/{dapr-send.md => dapr-invoke.md} (80%) rename pkg/{send/send.go => invoke/invoke.go} (98%) diff --git a/README.md b/README.md index d4236830..076b3907 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmd/invoke.go b/cmd/invoke.go new file mode 100644 index 00000000..b324d5a0 --- /dev/null +++ b/cmd/invoke.go @@ -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) +} diff --git a/cmd/send.go b/cmd/send.go deleted file mode 100644 index ba29c693..00000000 --- a/cmd/send.go +++ /dev/null @@ -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) -} diff --git a/docs/reference/dapr-send.md b/docs/reference/dapr-invoke.md similarity index 80% rename from docs/reference/dapr-send.md rename to docs/reference/dapr-invoke.md index b289ddbc..54a58889 100644 --- a/docs/reference/dapr-send.md +++ b/docs/reference/dapr-invoke.md @@ -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 | diff --git a/docs/reference/reference.md b/docs/reference/reference.md index e48c2c70..29c67c84 100644 --- a/docs/reference/reference.md +++ b/docs/reference/reference.md @@ -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) diff --git a/pkg/send/send.go b/pkg/invoke/invoke.go similarity index 98% rename from pkg/send/send.go rename to pkg/invoke/invoke.go index 989e2461..a26243b6 100644 --- a/pkg/send/send.go +++ b/pkg/invoke/invoke.go @@ -3,7 +3,7 @@ // Licensed under the MIT License. // ------------------------------------------------------------ -package send +package invoke import ( "bytes"