Updating the phone book application
The functionality that is added to this new version of the phone book utility is the following:
- The CSV file path can be optionally given as an environment variable named
PHONEBOOK
- The
list
command sorts the output based on the surname field
Although we could have given the path of the CSV file as a command-line argument instead of the value of an environment variable, it would have complicated the code, especially if that argument was made optional. More advanced Go packages such as viper
, which is presented in Chapter 6, Telling a UNIX System What to Do, simplify the process of parsing command-line arguments with the use of command-line options such as -f
followed by a file path or --filepath
.
The current default value of CSVFILE
is set to my home directory on a macOS Big Sur machine—you should change that default value to fit your needs or use a proper value for the PHONEBOOK
environment variable.