Z-Shell Auto-Complete for Apache Kafka CLI

blog-post

Make your Apache Kafka operational and development faster by typing less.

Introduction

The Z-Shell autocomplete functions are available from the following repository kzsh-autocomplete. It includes an optional cli command kaflist that can be natively compiled with GraalVM to allow for a faster auto-complete experience when topics, groups, and principals are fetched from the broker. This project is a work in progress with additional CLI commands to be added.

Please see README.md for complete setup instructions.

Auto-Complete Structure

Many Apache Kafka CLI tools have sub-commands, even though they look like arguments. For example, kafka-topics has --list and --create, which cannot be used together but can be placed anywhere in the command line argument list. These auto-complete scripts rely on those arguments happening early in the command, as they will control what additional arguments can then be used.

The connection configurations of --bootstrap-server and the various config arguments (e.g. --command-config) must exist before the topics, groups, and principals lookups can be done, since they are required for connecting to the Kafka cluster. Lookups of principals is only available by installing the kaflist GraalVM compiled utility.

These auto-complete scripts are lazy loaded on first use, following Z-Shell auto-complete syntax (_command) and placing them in the Z-Shell’s function path, $fpath.

Currently Supported Apache CLI Commands

  • kafka-topics
  • kafka-consumer-groups
  • kafka-console-producer
  • kafka-console-consumer

kafka-topics

Once --bootstrap-servers and optional --command-config are provided, --topics can auto-complete the actual list of topics available on the cluster. This greatly reduces typing mistakes and the need to copy and paste.

This command has five sub-commands (--list, --create, --alter, --delete, & --describe), each having additional allowed arguments. While kafka-topics does not require sub-commands to be entered early in the list, the auto-complete script is designed this way to avoid presenting options that are not applicable for a given sub-command.

kafka-consumer-groups

Once --bootstrap-servers and optional --command-config are provided, in addition to auto-complete of --topics, --groups can auto-complete the actual list of groups available in the cluster.

This command has five sub-commands (--list, --describe, --delete, --reset-offsets & --delete-offsets), each having additional allowed arguments. While kafka-consumer-groups does not require sub-commands to be entered early, the auto-complete script is designed this way to avoid presenting options that are not applicable for a given sub-command.

kafka-console-producer

There are a lot of options with the console producer, let the Z-Shell auto-complete help you select the topic, as well all the possible configuration properties.

kafka-console-consumer

Like the console producer, the consumer has many options. In addition to selecting the topic (and optional group), let the auto-complete help with property selection as well as deserializers.

Upcoming

The following commands are currently in progress and will be added soon.

  • kafka-configs
  • kafka-acls

Reach out

Please contact us if you have ideas or suggestions. Use the project’s GitHub Issues page for reporting specific issues related to this project.