ENGLISH

Building Modern CLI Applications in Go: Develop next-level CLIs to improve user experience, increase platform usage, and maximize production

Book information

Publisher
Packt Publishing
Year
2023
ISBN
1804611654, 9781804611654
Language
english
Format
PDF
Filesize
9 MB (9117543 bytes)
Pages
406\406
Time added
2023-03-26 03:58:08

Description

Evolve the humble CLI using Go and unleash the next generation of powerful, flexible, and empathy-driven interfaces Purchase of the print or Kindle book includes a free PDF eBook Key FeaturesDiscover how Go enables the development of elegant and intuitive CLIsExplore a range of CLI development aspects and pick up a vast array of best practicesCreate engaging and user-friendly interfaces and learn how to distribute themBook Description 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. What you will learnMaster the Go code structure, testing, and other essentialsAdd a colorful dashboard to your CLI using engaging ASCII bannersUse Cobra, Viper, and other frameworks to give your CLI an edgeHandle inputs, API commands, errors, and timeouts like a proTarget builds for specific platforms the right way using build tagsBuild with empathy, using easy bug submission and tracebackContainerize, distribute, and publish your CLIs quickly and easilyWho this book is for This book is for beginner- and intermediate-level Golang developers who take an interest in developing CLIs and enjoy learning by doing. You'll need an understanding of basic Golang programming concepts, but will require no prior knowledge of CLI design and development. This book helps you join a community of CLI developers and distribute within the popular Homebrew package management tool. Table of ContentsUnderstanding CLI StandardsStructuring Go Code for CLI ApplicationsDesign your tool and its purposePopular frameworks in Go to speed up and enhance CLI developmentProcessing Different Types of Input via Arguments and FlagsCalling External Processes and API commands and Handle Timeouts, and Error HandlingDeveloping for Different PlatformsBeing Clear, Concise and Consistent with CLIsEmpathic Side of DevelopmentInteractivity with Prompts and Terminal DashboardsCustomizing Go Binaries with Build TagsCross Compilation Across Different PlatformsUsing Containers for DistributionPublish your Go binary as a Homebrew Formula with GoReleaser Preface Title Page Copyright Dedication Contributors Table of Contents Part 1: Getting Started with a Solid Foundation Chapter 1: Understanding CLI Standards A brief introduction and history of the command line About the history Introducing the CLI The philosophy of CLI development Checklist for a successful CLI The guidelines Name Help and documentation Input Output Configuration Security Open source community Software lifespan and robustness Go for CLIs Summary Questions Answers Further reading Chapter 2: Structuring Go Code for CLI Applications Technical requirements Commonly used program layouts for robust applications Program layouts Common folders Determining use cases and requirements Use cases Requirements Disadvantages and benefits of use cases and requirements Use cases, diagrams, and requirements for a CLI Requirements for a metadata CLI Structuring an audio metadata CLI application Bounded context Language Entities and value objects Aggregation Service Events Repository Creating the structure Summary Questions Answers Further reading Chapter 3: Building an Audio Metadata CLI Technical requirements Defining the components cmd/ cmd/api/ cmd/cli/ cmd/cli/command extractors/ extractors/tags extractors/transcript internal/interfaces models/ services/metadata storage/ vendor/ Implementing use cases Uploading audio Requesting metadata Testing a CLI Manual testing Testing and mocking Summary Questions Answers Chapter 4: Popular Frameworks for Building CLIs Technical requirements Cobra – a library for building modern CLI applications Creating subcommands Global, local, and required flags Intelligent suggestions Automatically generated help and man pages Powering your CLI Viper – easy configuration for CLIs Configuration types Watching for live config changes Basic calculator CLI using Cobra and Viper The Cobra CLI commands The Viper configuration Running the basic calculator Summary Questions Answers Further reading Part 2: The Ins and Outs of a CLI Chapter 5: Defining the Command-Line Process Technical requirements Receiving the input and user interaction Defining subcommands, arguments, and flags Piping Signals and control characters User interaction Processing data Returning the resulting output and defining best practices Summary Questions Answers Further reading Chapter 6: Calling External Processes and Handling Errors and Timeouts Technical requirements Calling external processes The os/exec package Creating commands using the Cmd struct Running the command Interacting with REST APIs Get request Pagination Rate limiting Handling the expected – timeouts and errors Timeouts with external command processes Errors or panics with external command processes Timeouts and other errors with HTTP requests Summary Questions Answers Further reading Chapter 7: Developing for Different Platforms Technical requirements Packages for platform-independent functionality The os package The time package The path package The runtime package Implementing independent or platform-specific code Platform-independent code Platform-specific code Build tags for targeted platforms The build package Build tags OS-level differences Summary Questions Answers Further reading Part 3: Interactivity and Empathic Driven Design Chapter 8: Building for Humans versus Machines Technical requirements Building for humans versus machines Is it a TTY? Designing for a machine Designing for a human Increasing information density with ASCII art Displaying information with tables Clarifying with emojis Using color with intention Spinners and progress bars Disabling colors Being consistent across CLIs Naming Positional versus flag arguments Flag naming Usage Summary Questions Further reading Answers Chapter 9: The Empathic Side of Development Technical requirements Rewriting errors to be human-readable Guidelines for writing error messages Decorating errors Customizing errors Writing better error messages Providing debug and traceback information Logging data Initiating a logger Implementing a logger Trying out verbose mode to view stack traces Effortless bug submission Help, documentation, and support Generating help text Generating man pages Embedding empathy into your documentation Summary Questions Further reading Answers Chapter 10: Interactivity with Prompts and Terminal Dashboards Technical requirements Guiding users with prompts Designing a useful terminal dashboard Learning about Termdash Implementing a terminal dashboard Creating the terminal layer Creating the infrastructure layer Creating the container layer Creating the widgets layer Summary Questions Answers Further reading Part 4: Building and Distributing for Different Platforms Chapter 11: Custom Builds and Testing CLI Commands Technical requirements What are build tags and how can you use them? How to utilize build tags Creating a pro, free, and dev version Adding build tags to enable pprof Building with tags Building a free version Building a pro version Building to enable pprof on the pro version Testing CLI commands Mocking the HTTP client Handling test configuration Creating a test for a command Running the tests Summary Questions Answers Further reading Chapter 12: Cross-Compilation across Different Platforms Technical requirements Manual compilation versus build automation tools Using GOOS and GOARCH Compiling for Linux, macOS, and Windows Building using tags Building using the GOOS environment variable Building using the GOARCH environment variable Installing using tags and GOOS env va Installing using tags and GOARCH env var Scripting to compile for multiple platforms Creating a bash script to compile in Darwin or Linux Creating a PowerShell script in Windows Summary Questions Answers Further reading Chapter 13: Using Containers for Distribution Technical requirement Why use containers? Benefiting from containers Deciding not to use containers Building a simple Docker image Running a simple Docker container Testing with containers Creating the integration test file Writing the integration tests Writing the Dockerfiles Distributing with containers Building a new image to run as an executable Interacting with your container as an executable Mapping host machine to container file paths Reducing image size by using multi-stage builds Distributing your Docker image Depending on Docker Summary Questions Further reading Answers Chapter 14: Publishing Your Go Binary as a Homebrew Formula with GoReleaser Technical requirements GoReleaser workflow Defining the workflow Trigger release Tag and push the code Installing with Homebrew and Testing Summary Questions Further reading Answers Index About Packt Other Books You May Enjoy

Similar books

Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36

Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36

2010 · PDF

THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.

THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.

1858 · PDF

Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.

Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.

2022 · PDF

The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians

The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians

1809 · PDF