Chapter 7Using the Cobra CLI Framework
Up to this point, you’ve had to write all of the code to define the command-line interface for your programs. You’ve had to handle flags, environment variables, and the execution logic. Cobra[40] is a popular framework for designing CLI applications, and in this chapter, you’ll use it to handle the user interface of your program. If you work with Go and CLI tools, then it’s likely that you’ll encounter Cobra. Many modern tools are built with Cobra, including Kubernetes, Openshift, Podman, Hugo, and Docker.
Cobra provides a library that allows you to design CLI applications supporting POSIX[41]-compliant flags, subcommands, suggestions, autocompletion, and automatic help creation. It integrates with Viper ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access