summaryrefslogtreecommitdiff
path: root/conf/endpoint.go
blob: 1f8fa11b72c25fbe8022504d5e2e1cf4b87a38d7 (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main

import (
	"fmt"
	"log"
	db "sanine.net/git/phlox/db"
)


func CreateEndpoint() *Command {
	return &Command{
		Flag: "create-endpoint",
		Usage: "create a new endpoint",
		Invoke: func() {
			OpenDb()

			name := ReadLine("Endpoint Name: ")
			path := ReadLine("Endpoint Path: ")
			address := ReadLine("Endpoint Address: ")
			_, err := p.CreateEndpoint(name, path, address)
			if err != nil { log.Fatal(err) }
			fmt.Printf("created endpoint %v\n", name)
		},
	}
}


func GetEndpoint() db.Endpoint {
	OpenDb()
	name := ReadLine("Endpoint Name: ")
	endpoint, err := p.GetEndpointByName(name)
	if err != nil { log.Fatal(err) }
	return endpoint
}


func DeleteEndpoint() *Command {
	return &Command{
		Flag: "delete-endpoint",
		Usage: "delete an existing endpoint",
		Invoke: func() {
			endpoint := GetEndpoint()
			err := p.DeleteEndpoint(endpoint)
			if err != nil { log.Fatal(err) }
			fmt.Printf("deleted endpoint %v\n", endpoint.Name)
		},
	}
}


func SetPath() *Command {
	return &Command{
		Flag: "set-endpoint-path",
		Usage: "set the path of an existing endpoint",
		Invoke: func() {
			endpoint := GetEndpoint()
			fmt.Printf("Current Path: %v\n", endpoint.Path)
			path := ReadLine("New Path: ")
			err := p.SetEndpointPath(endpoint, path)
			if err != nil { log.Fatal(err) }
			fmt.Printf("updated path for endpoint %v\n", endpoint.Name)
		},
	}
}


func SetAddress() *Command {
	return &Command{
		Flag: "set-endpoint-address",
		Usage: "set the address of an existing endpoint",
		Invoke: func() {
			endpoint := GetEndpoint()
			fmt.Printf("Current Address: %v\n", endpoint.Address)
			address := ReadLine("New Address: ")
			err := p.SetEndpointAddress(endpoint, address)
			if err != nil { log.Fatal(err) }
			fmt.Printf("updated address for endpoint %v\n", endpoint.Name)
		},
	}
}


func ListEndpoints() *Command {
	return &Command{
		Flag: "list-endpoints",
		Usage: "list all endpoints",
		Invoke: func() {
			OpenDb()
			endpoints, err := p.AllEndpoints()
			if err != nil { log.Fatal(err) }
			fmt.Println("id\t\tname\t\tpath\t\taddress")
			fmt.Println("================================================================================")
			for _, endpoint := range endpoints {
				fmt.Printf("%v\t\t%v\t\t%v\t\t%v\n", endpoint.Id, endpoint.Name, endpoint.Path, endpoint.Address)
			}
		},
	}
}