From aa6d59fa56616a20745edcc0759baaa19152b919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Gallego=20Rodr=C3=ADguez?= Date: Wed, 23 Oct 2019 13:20:31 +0200 Subject: [PATCH] Fix for - and file adding a route. Move null routes to their own issue. Closes: #46 --- internal/cmd/route.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/cmd/route.go b/internal/cmd/route.go index 679efd4..0a600a2 100644 --- a/internal/cmd/route.go +++ b/internal/cmd/route.go @@ -1,6 +1,7 @@ package cmd import ( + "bytes" "log" "os" @@ -40,6 +41,28 @@ func init() { entrypoint, _ := cmd.Flags().GetString("entrypoint") urlPattern := args[0] + if len(args) > 1 && command == "" { + commandFile := args[1] + buf := new(bytes.Buffer) + if commandFile == "-" { + _, err := buf.ReadFrom(os.Stdin) + if err != nil { + log.Fatal(err) + } + } else { + file, err := os.Open(commandFile) + if err != nil { + log.Fatal(err) + } + defer file.Close() + _, err = buf.ReadFrom(file) + if err != nil { + log.Fatal(err) + } + } + command = buf.String() + } + // TODO: Read command from parameter, file or stdin if err := client.AddRoute(controlURL, urlPattern, method, entrypoint, command, os.Stdout); err != nil { log.Fatal(err)