Summary
In this section we has learned the skills to write basic and advanced command-line applications. We discussed how you can use the flag
package and os
package to receive signals from the user in the form of flags and arguments. We also discussed how to read data from os.Stdin
, which allows you to string multiple executables into a chain for processing.
We have discussed more advanced applications, namely the Cobra package and its accompanying generator binary, to build advanced command-line tooling with help text, shortcuts, and sub-commands.
Finally, we have talked about dealing with signals and providing cleanup on cancellation from these signals. This included a case study on why cancellation can be critical. The skills you have learned here will be critical in writing tooling in the future, from interacting with local files to interacting with services.
Quiz
Get hands-on with 1400+ tech skills courses.