/
setup.go
61 lines (48 loc) · 1.06 KB
/
setup.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
package commands
import (
"fmt"
"runtime"
"github.com/cristianoliveira/ergo/commands/setup"
"github.com/cristianoliveira/ergo/proxy"
)
// SetupCommand tries set ergo as the proxy on networking settings.
// For now, this feature is only supported for:
//
// - OSX
// - Linux-gnome
// - Windows
//
// Usage:
//
// `ergo setup osx`
//
type SetupCommand struct {
System string
Remove bool
}
var usage = `
List of supported systems:
-linux-gnome
-osx
-windows
For more support please open an issue on: https://github.com/cristianoliveira/ergo
`
// Execute apply the SetupCommand
func (c SetupCommand) Execute(config *proxy.Config) (string, error) {
fmt.Println("Current detected system: " + runtime.GOOS)
proxyURL := config.GetProxyPacURL()
configurator := setup.GetConfigurator(c.System)
if configurator == nil {
return "", fmt.Errorf(usage)
}
var err error
if c.Remove {
err = configurator.SetDown()
} else {
err = configurator.SetUp(proxyURL)
}
if err != nil {
return "", fmt.Errorf("Setup failed cause %s", err)
}
return "Setup executed", nil
}