-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.go
52 lines (47 loc) · 1.2 KB
/
import.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
//nolint:gochecknoglobals,gochecknoinits
package cmd
import (
"os"
"github.com/Defacto2/df2/cmd/internal/arg"
"github.com/Defacto2/df2/pkg/database"
"github.com/Defacto2/df2/pkg/importer"
"github.com/spf13/cobra"
)
var imrar arg.Import
var importCmd = &cobra.Command{
Use: "import (path to .rar)",
Short: "Import a .rar archive collection containing information NFO and text files.",
Aliases: []string{"im"},
GroupID: "group1",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
if err := cmd.Usage(); err != nil {
logr.Fatal(err)
}
return
}
im := importer.Importer{
RARFile: args[0],
Insert: imrar.Insert,
Limit: imrar.Limit,
Config: confg,
Logger: logr,
}
db, err := database.Connect(confg)
if err != nil {
logr.Fatal(err)
}
defer db.Close()
w := os.Stdout
if err := im.Import(db, w); err != nil {
logr.Fatal(err)
}
},
}
func init() {
rootCmd.AddCommand(importCmd)
importCmd.PersistentFlags().BoolVarP(&imrar.Insert, "insert", "i", false,
"insert the found text files metadata to the database")
importCmd.PersistentFlags().UintVarP(&imrar.Limit, "limit", "l", 0,
"limit the total number of found text files to process")
}