-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmdump.go
85 lines (66 loc) · 1.73 KB
/
pmdump.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
79
80
81
82
83
84
85
package main
import (
"flag"
"fmt"
"os"
"github.com/papermerge/pmdump/commands"
"github.com/papermerge/pmdump/config"
)
const PMDUMP_VERSION = "0.4"
var configFile = flag.String("c", "", "path to config file")
var targetFile = flag.String("f", "", "Target file - zipped tar archive file name were to dump")
var version = flag.Bool("version", false, "show version and exit")
const exportYaml = "export.yaml"
const exportCommand = "export"
const importCommand = "import"
func main() {
flag.Parse()
flag.Usage = func() {
w := flag.CommandLine.Output()
fmt.Fprintf(
w,
"Usage: %s [-c config.yaml] [-f archive.tar.gz] export | import \n",
os.Args[0],
)
flag.PrintDefaults()
fmt.Fprintf(w, "For more details check: https://github.com/papermerge/pmdump\n")
}
args := flag.Args()
if *version {
fmt.Println(PMDUMP_VERSION)
os.Exit(0)
}
if *configFile == "" {
fmt.Fprintf(os.Stderr, "Missing configuration. Did you forget -c flag?\n")
flag.Usage()
os.Exit(1)
}
if *targetFile == "" {
fmt.Fprintf(os.Stderr, "Missing target file. Did you forget -f flag?\n")
flag.Usage()
os.Exit(1)
}
settings, err := config.ReadConfig(*configFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", configFile, err)
os.Exit(1)
}
if len(args) == 0 {
fmt.Fprintf(os.Stderr, "Missing command: can be either %q or %q\n", exportCommand, importCommand)
os.Exit(1)
}
if args[0] == exportCommand {
commands.PerformExport(*settings, *targetFile, exportYaml)
} else if args[0] == importCommand {
commands.PerformImport(*settings, *targetFile, exportYaml)
} else {
fmt.Fprintf(
os.Stderr,
"Unknown command %q. Can be either %q or %q\n",
args[0],
exportCommand,
importCommand,
)
os.Exit(1)
}
}