Exercises

Powerful Command-Line Applications in Go — by Ricardo Gerardi (15 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Compiling Your Tool for Dif ferent Platforms | TOC | Wrapping Up 👉

You can improve your understanding of the concepts discussed here by doing these exercises:

  • Add another command-line flag, -b, to count the number of bytes in addition to words and lines.
  • Then, update the count function to accept another parameter, countBytes. When this input parameter is set to true, the function should count bytes. (Hint: check all the methods available for the type bufio.Scanner in the Go documentation.[12])
  • Write tests to ensure the new feature works as intended.

👈 Compiling Your Tool for Dif ferent Platforms | TOC | Wrapping Up 👉

Powerful Command-Line Applications in Go by Ricardo Gerardi can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.