December 2021
Intermediate to advanced
510 pages
11h 20m
English
Command-line tools should be helpful. Sometimes the user doesn’t know how to use a tool or they don’t remember all the options, so it’s helpful if your tool displays usage information.
Another benefit of using the flag package is that it provides automatic usage information if the user gives an invalid option or specifically requests help. You don’t have to do anything special to take advantage of this behavior either. Try it out by running your program with the -h option:
| | $ go build . |
| | $ ./todo -h |
| | Usage of ./todo: |
| | -complete int |
| | Item to be completed |
| | -list |
| | List all tasks |
| | -task string |
| | Task to be included in the ToDo list |
You didn’t have to include the -h flag in your code; the ...
Read now
Unlock full access