E-Book, Englisch, 406 Seiten
Montagnino Building Modern CLI Applications in Go
1. Auflage 2024
ISBN: 978-1-80461-369-6
Verlag: De Gruyter
Format: EPUB
Kopierschutz: 0 - No protection
Develop next-level CLIs to improve user experience, increase platform usage, and maximize production
E-Book, Englisch, 406 Seiten
ISBN: 978-1-80461-369-6
Verlag: De Gruyter
Format: EPUB
Kopierschutz: 0 - No protection
Although graphical user interfaces (GUIs) are intuitive and user-friendly, nothing beats a command-line interface (CLI) when it comes to productivity. Many organizations settle for a GUI without searching for alternatives that offer better accessibility and functionality. If this describes your organization, then pick up this book and get them to rethink that decision.
Building Modern CLI Applications in Go will help you achieve an interface that rivals a GUI in elegance yet surpasses it in high-performance execution. Through its practical, step-by-step approach, you'll learn everything you need to harness the power and simplicity of the Go language to build CLI applications that revolutionize the way you work.
After a primer on CLI standards and Go, you'll be launched into tool design and proper framework use for true development proficiency. The book then moves on to all things CLI, helping you master everything from arguments and flags to errors and API calls. Later, you'll dive into the nuances of empathic development so that you can ensure the best UX possible, before you finish up with build tags, cross-compilation, and container-based distribution.
By the end of this UX book, you'll be fully equipped to take the performance and flexibility of your organization's applications to the next level.
Fachgebiete
Weitere Infos & Material
Table of Contents - Understanding CLI Standards
- Structuring Go Code for CLI Applications
- Design your tool and its purpose
- Popular frameworks in Go to speed up and enhance CLI development
- Processing Different Types of Input via Arguments and Flags
- Calling External Processes and API commands and Handle Timeouts, and Error Handling
- Developing for Different Platforms
- Being Clear, Concise and Consistent with CLIs
- Empathic Side of Development
- Interactivity with Prompts and Terminal Dashboards
- Customizing Go Binaries with Build Tags
- Cross Compilation Across Different Platforms
- Using Containers for Distribution
- Publish your Go binary as a Homebrew Formula with GoReleaser
Preface
Who this book is for
What this book covers
, The Command-Line Interface (CLI) was initially created as a way to interact with Operating Systems before graphical user interfaces (GUIs) were invented. Although the GUI and web have become more common, there has been a resurgence of CLI development in recent years, particularly as an additional offering alongside a company’s API. In this chapter, you will learn about the history and anatomy of the CLI, the principles of UNIX, and why Go is a compelling language for building CLI applications.
, , This chapter serves as a guide for those who are unsure of how to begin creating a new CLI application. It covers popular ways to structure code, the concept of domain-driven design, and provides an example of a real-world use case for an audio metadata CLI application. By the end of the chapter, readers will have the necessary skills to develop an application based on their specific use cases and requirements.
, , This chapter provides hands-on learning by walking readers through building an audio metadata CLI’s use cases from start to finish. The code is available online and can be explored independently or alongside the chapter. Additionally, readers are encouraged to use their imagination to consider alternative ways to implement commands.
, , In this chapter, the most popular frameworks for developing modern CLI applications will be explored, with a focus on Cobra and its ability to quickly generate the scaffolding needed for a CLI application. Viper, which easily integrates with Cobra and provides extensive configuration options for applications, will also be discussed.
, , This chapter delves deeper into the anatomy of a command-line application, breaking down the different types of input such as subcommands, arguments, and flags, as well as other inputs such as stdin, signals, and control characters. It also provides examples of processing data for each input type and how to return the result in a way that is easily interpreted by both humans and computers.
, , This chapter will teach you how to call external processes and handle errors, including timeouts, that may occur when interacting with other commands or API services. The os/exec package is discussed, which allows for the creation and running of commands with various options, such as retrieving data from standard output and standard error pipes. Additionally, the net/http package is explored for calling external API service endpoints, and the chapter concludes with strategies for capturing and handling errors that may arise.
, , One of the things that makes building a command line application powerful is the ability to easily create code that can run on different machines, regardless of their operating systems. The os, time, path, and runtime packages are great tools to help developers create platform-independent code. In this chapter, we explore the functions and methods in these packages with simple examples, and show how to specify code for operating systems using build tags. By the end, you’ll feel more confident in your ability to write code that works across multiple platforms.
, , Developing your command-line application with your end user in mind is an important aspect to consider for better usability. In this chapter, we’ll explore ways to build for humans and scripts, use ASCII art to increase information density, and the importance of consistency for better navigation across different commands and subcommands.
, , In this chapter, you will learn how to use empathy to develop a better command-line interface (CLI) by considering the output and errors written, providing empathetic documentation, and readily available help and support for users. By rewriting errors in a way that users can easily understand, providing detailed logging and help features like man pages, usage examples, and bug submission options, developers can create an empathetic CLI that meets the user’s perspective and provides them with reassurance.
, , This chapter will show you how to improve usability by adding interactivity to your command-line application using either prompts or terminal dashboards. By providing examples and step-by-step instructions for creating surveys and dashboards, this chapter will help you build a more engaging and user-friendly interface. However, it is important to disable interactivity when not outputting to a terminal.
, , To enhance the stability and scalability of a growing Go project, it is essential to incorporate build tags with Boolean logic to enable targeted builds and testing. This chapter demonstrates the use of build tags and testing through a real-world example, the audiofile CLI, and covers topics such as integrating levels, enabling profiling, and testing HTTP clients.
, , This chapter explains cross-compilation in Go, including the different operating systems and architectures that Go can compile and how to determine which is needed. It covers topics such as manual compilation versus build automation tools, using GOOS and GOARCH, compiling for Linux, MacOS, and Windows, and scripting to compile for multiple platforms.
, , In this chapter, we’ll dive into Docker containers and how they can benefit you when testing and sharing your CLI application. We’ll begin with the basics and gradually move onto more complex topics, such as using containers for integration testing. Additionally, we’ll weigh up the pros and cons of using Docker, helping you determine whether it’s the right choice for you. By the end of the chapter, you’ll be equipped to containerize your application, test it through Docker, and share it with others via Docker Hub.
, , In this chapter, you’ll learn how to automate the release of a Go binary as a Homebrew formula using GoReleaser and GitHub Actions. GoReleaser simplifies the creation, testing, and distribution of Go binaries, and GitHub Actions is a CI/CD platform that automates software development workflows. By creating a Homebrew tap for your application, you can simplify the installation process for MacOS users and reach a larger audience.
To get the most out of this book
| Software/hardware covered in the book | Operating system requirements |
| Go 1.19 | Windows, macOS, or... |




