forked from cristianoliveira/ergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (59 loc) · 1.25 KB
/
main.go
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
package main
import (
"flag"
"fmt"
"github.com/cristianoliveira/ergo/commands"
"github.com/cristianoliveira/ergo/proxy"
"os"
)
var VERSION string
const USAGE = `
Ergo proxy.
The local proxy agent for multiple services development.
Usage:
ergo [options]
ergo run [options]
ergo list
ergo list-names
ergo url <name>
Options:
-h Shows this message.
-v Shows ergo's version.
Run:
-p Set ports to proxy
`
func main() {
help := flag.Bool("h", false, "Shows ergo's help.")
version := flag.Bool("v", false, "Shows ergo's version.")
flag.Parse()
if *help {
fmt.Println(USAGE)
os.Exit(0)
}
if *version {
fmt.Println(VERSION)
os.Exit(0)
}
config := proxy.NewConfig()
command := flag.NewFlagSet(os.Args[1], flag.ExitOnError)
command.StringVar(&config.Port, "p", "2000", "Set port to the proxy")
command.StringVar(&config.Port, "p", "2000", "Set port to the proxy")
config.Services = proxy.LoadConfig("./.ergo")
switch os.Args[1] {
case "list":
commands.List(config)
case "list-names":
commands.ListNames(config)
case "url":
if len(os.Args) != 3 {
fmt.Println(USAGE)
os.Exit(0)
}
name := os.Args[2]
commands.Url(name, config)
case "run":
commands.Run(config)
default:
fmt.Println(USAGE)
}
}