-
Notifications
You must be signed in to change notification settings - Fork 0
/
apis.go
56 lines (51 loc) · 1.63 KB
/
apis.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
//nolint:gochecknoglobals,gochecknoinits
package cmd
import (
"errors"
"os"
"github.com/Defacto2/df2/cmd/internal/arg"
"github.com/Defacto2/df2/cmd/internal/run"
"github.com/Defacto2/df2/pkg/database"
"github.com/spf13/cobra"
)
var apis arg.APIs
// apisCmd represents the demozoo command.
var apisCmd = &cobra.Command{
Use: "apis",
Short: "Batch data synchronization with remote APIs.",
Long: `Run batch data synchronizations with the remote APIs hosted
on demozoo.org and pouet.net. All these commands are SLOW and
require the parsing of 10,000s of records.`,
Aliases: []string{"api"},
GroupID: "group3",
Example: ` df2 apis [--refresh|--pouet|--msdos|--windows]`,
Run: func(cmd *cobra.Command, args []string) {
db, err := database.Connect(confg)
if err != nil {
logr.Fatal(err)
}
defer db.Close()
err = run.APIs(db, os.Stdout, apis)
switch {
case errors.Is(err, run.ErrArg):
if err := cmd.Usage(); err != nil {
logr.Fatal(err)
}
case err != nil:
logr.Error(err)
}
},
}
func init() {
rootCmd.AddCommand(apisCmd)
apisCmd.Flags().BoolVarP(&apis.Refresh, "refresh", "r", false,
"replace any empty data cells with fetched demozoo data\n"+
"demozoo ids that return 404 not found errors are removed")
apisCmd.Flags().BoolVarP(&apis.Pouet, "pouet", "p", false,
"sync local files with pouet ids linked on demozoo")
apisCmd.Flags().BoolVarP(&apis.SyncDos, "msdos", "d", false,
"scan demozoo for missing local msdos bbstros and cracktros")
apisCmd.Flags().BoolVarP(&apis.SyncWin, "windows", "w", false,
"scan demozoo for missing local windows bbstros and cracktros")
apisCmd.Flags().SortFlags = false
}