-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.go
68 lines (54 loc) · 1.55 KB
/
export.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
// Package ghligh, a pdf highlights swiss knife
//
// Copyright (c) 2024 Francesco Orlando
//
// This file is part of a program licensed under the GNU General Public License, version 2.
// You should have received a copy of the GNU General Public License along with this program.
// If not, see the LICENSE.md file in the root directory of this repository or visit
// <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>.
package main
import (
"github.com/orlandofra/ghligh/document"
"fmt"
"os"
"encoding/json"
)
func commandExport(args []string){
fromFiles, toFiles := parse2Files(args)
if fromFiles == nil {
fmt.Fprintf(os.Stderr, "ghligh: please specify at least one pdf file via -f or --from for export\n")
os.Exit(1)
}
if !areValidPDFs(fromFiles){
os.Exit(1)
}
var exportedDocs []interface{}
for _, file := range(fromFiles){
doc, err := ghligh.Open(file)
if err != nil {
fmt.Fprintf(os.Stderr, "ghligh: error opening %s: %v\n", file, err)
continue
}
exportedData, err := doc.Export()
if err != nil {
fmt.Fprintf(os.Stderr, "ghligh: error exporting highlights of file %s: %v\n", file, err)
continue
}
exportedDocs = append(exportedDocs, exportedData)
doc.Close()
}
jsonData, err := json.MarshalIndent(exportedDocs, "", " ")
if err != nil {
fmt.Fprintf(os.Stderr, "ghligh: could not Indent %v\n", err)
os.Exit(1)
}
if toFiles == nil {
fmt.Printf(string(jsonData))
} else {
for _, file := range(toFiles){
saveToJSON(jsonData, file)
}
/* for file in toFiles, create file and save
it as json */
}
}