main.go raw
1 package main
2
3 import (
4 "bytes"
5 "encoding/json"
6 "os"
7
8 "github.com/p9c/p9/pkg/qu"
9
10 _ "github.com/p9c/p9/pkg/gel/gio/app/permission/networkstate" // todo: integrate this into routeable package
11 _ "github.com/p9c/p9/pkg/gel/gio/app/permission/storage" // this enables the home folder appdata directory to work on android (and ios)
12
13 "github.com/p9c/p9/pkg/log"
14 "github.com/p9c/p9/pod/config"
15 "github.com/p9c/p9/pod/podcfgs"
16 "github.com/p9c/p9/pod/podhelp"
17 "github.com/p9c/p9/pod/state"
18 "github.com/p9c/p9/version"
19
20 // This ensures the database drivers get registered
21 _ "github.com/p9c/p9/pkg/database/ffldb"
22
23 // _ "github.com/p9c/p9/pkg/gel/gio/app/permission/bluetooth"
24 // _ "github.com/p9c/p9/pkg/gel/gio/app/permission/camera"
25 )
26
27 func main() {
28 <-Main()
29 }
30
31 func Main() (quit qu.C) {
32 quit = qu.T()
33 go func() {
34 log.SetLogLevel("trace")
35 T.Ln(os.Args)
36 T.Ln(version.Get())
37 var cx *state.State
38 var e error
39 if cx, e = state.GetNew(podcfgs.GetDefaultConfig(), podhelp.HelpFunction, quit); E.Chk(e) {
40 fail()
41 }
42
43 // fail()
44 // if e = debugConfig(cx.Config); E.Chk(e) {
45 // }
46
47 D.Ln("running command:", cx.Config.RunningCommand.Name)
48 if e = cx.Config.RunningCommand.Entrypoint(cx); E.Chk(e) {
49 fail()
50 }
51 quit.Q()
52 }()
53 return quit
54 }
55
56 func fail() {
57 os.Exit(1)
58 }
59
60 func debugConfig(c *config.Config) (e error) {
61 c.ShowAll = true
62 defer func() { c.ShowAll = false }()
63 var j []byte
64 if j, e = c.MarshalJSON(); E.Chk(e) {
65 return
66 }
67 var b []byte
68 jj := bytes.NewBuffer(b)
69 if e = json.Indent(jj, j, "", "\t"); E.Chk(e) {
70 return
71 }
72 T.Ln("\n"+jj.String())
73 return
74 }
75