Skip to content

Commit

Permalink
improves usage information.
Browse files Browse the repository at this point in the history
  • Loading branch information
fgeller committed Mar 31, 2016
1 parent e4260fb commit de2aeb1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
30 changes: 27 additions & 3 deletions consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,39 @@ func parseOffsets(str string) (map[int32]interval, error) {

func consumeCommand() command {
consume := flag.NewFlagSet("consume", flag.ExitOnError)
consume.StringVar(&config.consume.args.topic, "topic", "", "Topic to consume.")
consume.StringVar(&config.consume.args.topic, "topic", "", "Topic to consume (required).")
consume.StringVar(&config.consume.args.brokers, "brokers", "localhost:9092", "Comma separated list of brokers. Port defaults to 9092 when omitted.")
consume.StringVar(&config.consume.args.offsets, "offsets", "", "Specifies what messages to read by partition and offset range.")
consume.StringVar(&config.consume.args.offsets, "offsets", "", "Specifies what messages to read by partition and offset range (defaults to all).")
consume.DurationVar(&config.consume.timeout, "timeout", time.Duration(0), "Timeout after not reading messages (default 0 to disable).")

consume.Usage = func() {
fmt.Fprintln(os.Stderr, "Usage of consume:")
consume.PrintDefaults()
fmt.Fprintln(os.Stderr, ` `) // TODO
fmt.Fprintln(os.Stderr, `
Offsets can be specified as a comma-separated list of intervals:
partition1:start-end,partition2:start-end
Examples:
To consume messages from partition 0 between offsets 10 and 20 (inclusive).
0:10-20
To consume messages until offset 10 from all partitions:
-10
To consume from multiple partitions:
0:4-,2:1-10,6
This would consume messages from three partitions:
- Anything from partition 0 starting at offset 4.
- Messages between offsets 1 and 10 from partition 2.
- Anything from partition 6.
`)
os.Exit(2)
}

Expand Down
4 changes: 2 additions & 2 deletions produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type message struct {

func produceCommand() command {
produce := flag.NewFlagSet("produce", flag.ExitOnError)
produce.StringVar(&config.produce.args.topic, "topic", "", "Topic to produce to.")
produce.StringVar(&config.produce.args.topic, "topic", "", "Topic to produce to (required).")
produce.StringVar(&config.produce.args.brokers, "brokers", "localhost:9092", "Comma separated list of brokers. Port defaults to 9092 when omitted.")

produce.Usage = func() {
Expand Down Expand Up @@ -64,7 +64,7 @@ Keep reading input from stdin until interrupted (via ^C).
bonjour.
Sent message to partition 0 at offset 5.
$ kt consume -topic greetings -json -timeout 1s -offsets 4:
$ kt consume -topic greetings -timeout 1s -offsets 0:4-
{"partition":0,"offset":4,"key":"hello.","message":"hello."}
{"partition":0,"offset":5,"key":"bonjour.","message":"bonjour."}
`)
Expand Down

0 comments on commit de2aeb1

Please sign in to comment.