aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/src/cmd/target.go
blob: 1d56c39540a03db127969db581dbc53d99ea1f2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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/utils"
    "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
    }

    utils.Error("Unknown target argument '" + targetArgument + ": Use 'local', 'cloud' or an URL")
    return nil
}