Skip to content

Commit f4eda5b

Browse files
authored
Merge pull request #1292 from ripienaar/watch_opts
Additional KV Watch options
2 parents e5087cb + 1668f41 commit f4eda5b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

cli/kv_command.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ type kvCommand struct {
6464
mirrorDomain string
6565
sources []string
6666
compression bool
67+
includeHistory bool
68+
includeDeletes bool
69+
updatesOnly bool
6770
}
6871

6972
func configureKVCommand(app commandHost) {
@@ -158,6 +161,10 @@ for an indefinite period or a per-bucket configured TTL.
158161
watch := kv.Command("watch", "Watch the bucket or a specific key for updated").Action(c.watchAction)
159162
watch.Arg("bucket", "The bucket to act on").Required().StringVar(&c.bucket)
160163
watch.Arg("key", "The key to act on").Default(">").StringVar(&c.key)
164+
watch.Flag("history", "Includes historic values").UnNegatableBoolVar(&c.includeHistory)
165+
watch.Flag("deletes", "Includes deletes in watched values").Default("true").BoolVar(&c.includeDeletes)
166+
watch.Flag("updates", "Only show new values written").UnNegatableBoolVar(&c.updatesOnly)
167+
watch.Flag("revision", "Starts from a certain revision").Uint64Var(&c.revision)
161168

162169
ls := kv.Command("ls", "List available buckets or the keys in a bucket").Alias("list").Action(c.lsAction)
163170
ls.Arg("bucket", "The bucket to list the keys").StringVar(&c.bucket)
@@ -804,7 +811,21 @@ func (c *kvCommand) watchAction(_ *fisk.ParseContext) error {
804811

805812
ctx := context.Background()
806813

807-
watch, err := store.Watch(ctx, c.key)
814+
var opts []jetstream.WatchOpt
815+
if !c.includeDeletes {
816+
opts = append(opts, jetstream.IgnoreDeletes())
817+
}
818+
if c.includeHistory {
819+
opts = append(opts, jetstream.IncludeHistory())
820+
}
821+
if c.updatesOnly {
822+
opts = append(opts, jetstream.UpdatesOnly())
823+
}
824+
if c.revision > 0 {
825+
opts = append(opts, jetstream.ResumeFromRevision(c.revision))
826+
}
827+
828+
watch, err := store.Watch(ctx, c.key, opts...)
808829
if err != nil {
809830
return err
810831
}

0 commit comments

Comments
 (0)