forked from FactomProject/walletapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commandline.go
76 lines (68 loc) · 1.49 KB
/
commandline.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
// Copyright 2015 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package main
import (
"bufio"
"fmt"
"io"
"os"
"runtime"
"strings"
"time"
"github.com/FactomProject/FactomCode/util"
fct "github.com/FactomProject/factoid"
)
var _ = fmt.Println
var _ fct.Transaction
var _ = time.Now
var cfg = util.ReadConfig().Wallet
func main() {
var configDir string
var staticDir string
switch runtime.GOOS {
case "windows":
configDir = cfg.BoltDBPath
staticDir = "./staticfiles/"
case "darwin":
configDir = os.Getenv("HOME") + "/.factom/"
staticDir = "/Applications/FactomApps/staticfiles/"
default:
configDir = os.Getenv("HOME") + "/.factom/"
staticDir = "/usr/share/factom/walletapp/"
}
err := os.MkdirAll(configDir, 0750)
if err != nil {
fmt.Println("mkdir failed %v %v", configDir, err)
return
}
state := NewState(configDir + "factoid_wallet_bolt.db")
go startServer(state, staticDir)
Open("http://localhost:8096")
run(state, os.Stdin, true)
}
var fsprompt string = "===============> "
func run(state IState, reader io.Reader, prompt bool) {
r := bufio.NewScanner(reader)
if prompt {
fmt.Print(fsprompt)
}
for r.Scan() {
line := r.Text()
args := strings.Fields(string(line))
err := state.Execute(args)
if err != nil {
fmt.Println(err)
c, _ := state.GetCommand(args)
if c != nil {
fmt.Println(c.ShortHelp())
}
}
if prompt {
fmt.Print(fsprompt)
}
}
if prompt {
fmt.Println()
}
}