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-configs
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.
kafka-configs
Adjust the configuration of a kafka resource. The kafka-configs
command is rather complex, it is quite possible that the auto-complete may show its limitations (e.g. use of –clients and –users concurrently).
Please update to the latest kaflist
to get support for broker-ids, ips, and clients in the autocomplete.
Troubleshooting
- Be sure to set your
fpath
prior to enablingcompinit
in your.zshrc
file.
fpath=(~/.zsh/functions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.9/functions)
autoload -Uz compinit && compinit
If newly added autocompletes are not working, either exit your shell and create a new one, or try
rehash
. This command updates the shell’s internal hash tables of executables.Updating a script
If you update a script provided in this project, to reload it successfully within your current shell, do the following (adjusting to where you are placing the functions):
cp ./functions/_kafka-topics ~/.zsh/functions
unfunction _kafka-topics
autoload -Uz _kafka-topics
Upcoming
The following command is currently in progress and will be added soon.
- 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.