-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.go
65 lines (52 loc) · 1.64 KB
/
dump.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
/*
Copyright © 2023 Vance Longwill <vance@evren.co.uk>
*/
package cmd
import (
"dscli/dumper"
"encoding/json"
"os"
"cloud.google.com/go/datastore"
"github.com/spf13/cobra"
)
// dumpCmd represents the dump command
var dumpCmd = &cobra.Command{
Use: "dump",
Short: "Get a dump of all entries for a given entity",
Long: `Runs a GetAll query for the given entity until all entries have been exhausted`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
dsClient, err := datastore.NewClient(ctx, project)
if err != nil {
return err
}
enc := json.NewEncoder(os.Stdout)
entityName := "RESTTransaction"
dumper := dumper.New(dumper.Config{
Client: dsClient,
Encoder: enc,
BatchSize: batchSize,
EntityName: entityName,
})
return dumper.Dump(ctx)
},
}
var (
entity string
output string
batchSize int
)
func init() {
dumpCmd.Flags().StringVarP(&entity, "entity", "e", "", "the datastore entity name")
dumpCmd.Flags().IntVarP(&batchSize, "batch-size", "b", 1000, "the number of entities to fetch in a single page")
dumpCmd.Flags().StringVarP(&output, "output", "o", "json", "the output format (defaults to JSON)")
dumpCmd.MarkFlagRequired("entity")
rootCmd.AddCommand(dumpCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// dumpCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// dumpCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}