-
Notifications
You must be signed in to change notification settings - Fork 0
/
nanafshi.go
70 lines (59 loc) · 1.09 KB
/
nanafshi.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
package nanafshi
import (
"fmt"
"io"
"os"
"time"
"github.com/tokibi/nanafshi/config"
)
const version = "0.1.1"
var (
opts Option
conf *config.Config
)
type Nanafshi struct {
Out, Err io.Writer
}
const (
ExitCodeOK = iota
ExitCodeError
)
func newRoot(conf *config.Config) *Root {
now := time.Now()
return &Root{
Node: NewNode(),
NodeInfo: NodeInfo{
Mode: os.ModeDir | 0777,
Creation: now,
LastMod: now,
},
Services: conf.Services,
}
}
func (n Nanafshi) Run(args []string) int {
parser := newOptionParser(&opts)
args, err := parser.ParseArgs(args)
if err != nil {
parser.WriteHelp(os.Stderr)
return ExitCodeError
}
if opts.Version {
fmt.Printf("nanafshi version %s\n", version)
return ExitCodeOK
}
if len(args) < 1 {
parser.WriteHelp(os.Stderr)
return ExitCodeError
}
conf, err = config.LoadFile(opts.ConfPath)
if err != nil {
fmt.Fprintln(n.Out, err)
return ExitCodeError
}
root := newRoot(conf)
if err = root.MountAndServe(args[0], opts.Verbose); err != nil {
fmt.Fprintln(os.Stderr, err)
return ExitCodeError
}
return ExitCodeOK
}