Skip to content

Commit

Permalink
add option for function invoke in watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Vlasic committed Aug 17, 2021
1 parent 3002574 commit 011a0ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/mantil/cmd/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var invokeCmd = &cobra.Command{
}

func init() {
invokeCmd.Flags().StringP("data", "d", "", "Data for the request")
invokeCmd.Flags().StringP("data", "d", "", "Data for the request.")
invokeCmd.Flags().BoolP("include", "i", false, "Include response headers in the output.")
invokeCmd.Flags().BoolP("logs", "l", false, "Include lambda execution logs.")
rootCmd.AddCommand(invokeCmd)
Expand Down
22 changes: 21 additions & 1 deletion cmd/mantil/cmd/watch.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cmd

import (
"fmt"
"log"

"github.com/atoz-technology/mantil-cli/internal/commands/deploy"
"github.com/atoz-technology/mantil-cli/internal/commands/invoke"
"github.com/atoz-technology/mantil-cli/internal/commands/watch"
"github.com/spf13/cobra"
)
Expand All @@ -14,24 +16,42 @@ var watchCmd = &cobra.Command{
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
p, config, path, token := findProject(args)
method := cmd.Flag("method").Value.String()
data := cmd.Flag("data").Value.String()

if method != "" && p.ApiURL == "" {
log.Fatalf("api URL for the project does not exist")
}
endpoint := fmt.Sprintf("%s/%s", p.ApiURL, method)

aws, err := initialiseAWSSDK(config.Name, token)
if err != nil {
log.Fatal(err)
}

d, err := deploy.New(p, aws, path, token)
if err != nil {
log.Fatal(err)
}

watch.Start(path, func() {
log.Println("changes detected - starting deploy")
defer log.Println("deploy finished")
if err := d.Deploy(); err != nil {
log.Fatal(err)
}
log.Println("deploy finished")
if method != "" {
log.Printf("invoking method %s", method)
if err := invoke.Endpoint(endpoint, data, false); err != nil {
log.Print(err)
}
}
})
},
}

func init() {
watchCmd.Flags().StringP("method", "m", "", "Method to invoke after deploying changes.")
watchCmd.Flags().StringP("data", "d", "", "Data for the method request.")
rootCmd.AddCommand(watchCmd)
}

0 comments on commit 011a0ba

Please sign in to comment.