aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/cmd/target.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/cmd/target.go')
-rw-r--r--client/go/cmd/target.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/client/go/cmd/target.go b/client/go/cmd/target.go
new file mode 100644
index 00000000000..4c1ead7f74e
--- /dev/null
+++ b/client/go/cmd/target.go
@@ -0,0 +1,60 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Models a target for Vespa commands
+// author: bratseth
+
+package cmd
+
+import (
+ "github.com/vespa-engine/vespa/util"
+ "strings"
+)
+
+type target struct {
+ deploy string
+ query string
+ document string
+}
+
+type context int32
+const (
+ deployContext context = 0
+ queryContext context = 1
+ documentContext context = 2
+)
+
+func getTarget(targetContext context) *target {
+ if strings.HasPrefix(targetArgument, "http") {
+ // TODO: Add default ports if missing
+ switch targetContext {
+ case deployContext:
+ return &target{
+ deploy: targetArgument,
+ }
+ case queryContext:
+ return &target{
+ query: targetArgument,
+ }
+ case documentContext:
+ return &target{
+ document: targetArgument,
+ }
+ }
+ }
+
+ // Otherwise, target is a name
+
+ if targetArgument == "" || targetArgument == "local" {
+ return &target{
+ deploy: "http://127.0.0.1:19071",
+ query: "http://127.0.0.1:8080",
+ document: "http://127.0.0.1:8080",
+ }
+ }
+
+ if targetArgument == "cloud" {
+ return nil // TODO
+ }
+
+ util.Error("Unknown target argument '" + targetArgument + ": Use 'local', 'cloud' or an URL")
+ return nil
+} \ No newline at end of file