Fix for - and file adding a route. Move null routes to their own issue.

Closes: #46
This commit is contained in:
César Gallego Rodríguez
2019-10-23 13:20:31 +02:00
parent 034a5ab677
commit aa6d59fa56
+23
View File
@@ -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)