-
Notifications
You must be signed in to change notification settings - Fork 13
/
cmds.go
102 lines (92 loc) · 2.15 KB
/
cmds.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package cmds
import (
"fmt"
"github.com/donkeysharp/gocho/pkg/config"
"github.com/donkeysharp/gocho/pkg/info"
"github.com/donkeysharp/gocho/pkg/node"
"github.com/urfave/cli"
)
func ConfigureAction(c *cli.Context) error {
err := config.ConfigureWizard()
if err != nil {
return cli.NewExitError(err, 1)
}
return nil
}
func StartAction(c *cli.Context) error {
fmt.Println("Starting Gocho Node...")
conf := &config.Config{}
conf.Debug = c.Bool("debug")
conf.LocalPort = c.String("local-port")
conf.WebPort = c.String("share-port")
conf.ShareDirectory = c.String("dir")
conf.NodeId = c.String("id")
if conf.NodeId == "" || conf.ShareDirectory == "" {
fmt.Println("Both --dir and --id should be set.")
fmt.Println("Checking config file.")
var err error
conf, err = config.LoadConfig()
if err != nil {
return cli.NewExitError(err, 1)
}
}
fmt.Println("Configuration loaded")
fmt.Println("---")
fmt.Println(conf)
fmt.Println("---")
node.Serve(conf)
return nil
}
func New() *cli.App {
app := cli.NewApp()
app.Name = info.APP_NAME
app.Usage = "Auto-discovery local area network file sharing"
app.Version = info.VERSION
app.Authors = []cli.Author{
cli.Author{
Name: "Sergio Guillen Mantilla",
Email: "serguimant@gmail.com",
},
}
app.Commands = []cli.Command{
{
Name: "start",
Usage: "Start Gocho node",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "Start gocho in debug mode",
},
cli.StringFlag{
Name: "id",
Usage: "Node ID that will be shared to other peers",
EnvVar: "GOCHO_ID",
},
cli.StringFlag{
Name: "dir",
Usage: "Directory to share",
EnvVar: "GOCHO_DIR",
},
cli.StringFlag{
Name: "share-port",
Usage: "Port that will be exposed for file sharing",
EnvVar: "GOCHO_SHARE_PORT",
Value: "5555",
},
cli.StringFlag{
Name: "local-port",
Usage: "Port for local dashboard",
EnvVar: "GOCHO_LOCAL_PORT",
Value: "1337",
},
},
Action: StartAction,
},
{
Name: "configure",
Usage: "Create a configuration file for Gocho node",
Action: ConfigureAction,
},
}
return app
}