-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (71 loc) · 1.59 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"context"
"errors"
"flag"
"fmt"
"os"
"path/filepath"
ff "github.com/peterbourgon/ff/v3"
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/jtolio/jam/utils"
_ "github.com/jtolio/jam/backends/fs"
_ "github.com/jtolio/jam/backends/s3"
_ "github.com/jtolio/jam/backends/sftp"
_ "github.com/jtolio/jam/backends/storj"
)
var (
sysFlags = flag.NewFlagSet("", flag.ExitOnError)
sysFlagConfig = sysFlags.String("config",
filepath.Join(homeDir(), ".jam", "jam.conf"),
"path to config file")
sysFlagLogLevel = sysFlags.String("log.level", "normal",
"default log level. can be:\n\tdebug, normal, urgent, or none")
cmdRoot = &ffcli.Command{
ShortHelp: "jam preserves your data",
ShortUsage: fmt.Sprintf("%s [opts] <subcommand> [opts]", os.Args[0]),
Subcommands: []*ffcli.Command{
cmdIntegrity,
cmdKeys,
cmdLs,
cmdMount,
cmdRename,
cmdRevertTo,
cmdRm,
cmdSnaps,
cmdStore,
cmdUnsnap,
cmdUtils,
cmdWebdav,
},
FlagSet: sysFlags,
Options: []ff.Option{
ff.WithAllowMissingConfigFile(true),
ff.WithConfigFileParser(ff.PlainParser),
ff.WithConfigFileFlag("config"),
},
Exec: help,
}
)
func main() {
err := func() error {
err := cmdRoot.Parse(os.Args[1:])
if err != nil {
return err
}
logLevel, err := utils.ParseLogLevel(*sysFlagLogLevel)
if err != nil {
return err
}
return cmdRoot.Run(
utils.ContextWithLogger(context.Background(),
utils.StandardLogger(logLevel)))
}()
if err != nil {
if errors.Is(err, flag.ErrHelp) {
return
}
fmt.Fprintf(os.Stderr, "error: %+v\n", err)
os.Exit(1)
}
}