forked from netgusto/nodebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (54 loc) · 1.7 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
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/alecthomas/kingpin"
"github.com/markbates/pkger"
"github.com/netgusto/nodebook/src/core"
"github.com/pkg/errors"
)
var _ = pkger.Include("/dist/frontend/")
var _ = pkger.Include("/src/recipes/")
func main() {
webCmd := kingpin.Command("web", "Web")
webCmdPath := webCmd.Arg("notebookspath", "path to notebooks").Default(".").ExistingDir()
webCmdDocker := webCmd.Flag("docker", "Use docker").Bool()
webCmdPort := webCmd.Flag("port", "HTTP port").Default("8000").Int()
webCmdBindAddress := webCmd.Flag("bindaddress", "Bind address").Default("127.0.0.1").String()
cliCmd := kingpin.Command("cli", "cli")
cliCmdPath := cliCmd.Arg("notebookspath", "path to notebooks").Default(".").ExistingDir()
cliCmdDocker := cliCmd.Flag("docker", "Use docker").Bool()
args := os.Args[1:]
if len(args) == 0 || (args[0] != webCmd.FullCommand() && args[0] != cliCmd.FullCommand()) {
args = append([]string{"web"}, args...)
}
selected, err := kingpin.CommandLine.Parse(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
switch selected {
case webCmd.FullCommand():
absPath, err := absolutizePath(*webCmdPath)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
core.WebRun(absPath, *webCmdDocker, *webCmdBindAddress, *webCmdPort)
case cliCmd.FullCommand():
absPath, err := absolutizePath(*cliCmdPath)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
core.CliRun(absPath, *cliCmdDocker)
}
}
func absolutizePath(notebooksPath string) (string, error) {
absBookPath, err := filepath.Abs(notebooksPath)
if err != nil {
return "", errors.Wrapf(err, "Could not determine absolute path for \"%s\"", notebooksPath)
}
return absBookPath, nil
}