-
Notifications
You must be signed in to change notification settings - Fork 15
/
history.go
45 lines (38 loc) · 938 Bytes
/
history.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
package cmd
import (
"context"
"encoding/json"
"os"
"github.com/cybozu-go/well"
"github.com/spf13/cobra"
)
var historyCount int
// historyCmd represents the history command
var historyCmd = &cobra.Command{
Use: "history",
Short: "show the hostname of the current history process",
Long: `Show the hostname of the current history process.`,
RunE: func(cmd *cobra.Command, args []string) error {
well.Go(func(ctx context.Context) error {
records, err := storage.GetRecords(ctx, int64(historyCount))
if err != nil {
return err
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
for _, r := range records {
err = enc.Encode(r)
if err != nil {
return err
}
}
return nil
})
well.Stop()
return well.Wait()
},
}
func init() {
historyCmd.Flags().IntVarP(&historyCount, "count", "n", 0, "limit the number of operations to show")
rootCmd.AddCommand(historyCmd)
}