We use Elixir's escript to create a command line application to solve the challenge from lesson 7. It's a clone of the core functionality of Unix's "tail" command.
Unlike the "wc" clone we built previously, tail requires the ability to parse flags with arguments, e.g. tail filename.txt -n 30
. We also introduce the one-liner syntax for if-else blocks.
3 Comments
I found that if I used the switch "--lines2323" for example, it would still read the file and show the last 10 lines. In your example, it shows the help message. I changed "switches" to "strict" in cli.ex, and now it shows the help message as expected, along with working as expected. I also found the same in the Word Count example, but didn't find the problem until now... Might be due to the version of Elixir I am using is 1.10, and not 1.5 as used in the video, and OptionParser.parse may have changed functionality in that time.
Great discovery, Owen! Have you gone through the ASDF setup video yet? It makes switching versions trivial and you can define them per project with a
.tool-versions
file.In general, you don't need to worry about any breaking changes from language versions. Until there's a v2, if there ever is, anything after 1.0 should be fine.
I've had a look at ASDF, but haven't set it up as yet. I'm only just coming back into programming after about 20 years - did a lot of Assembly and C++ back then. Slowly working my way through screen casts and books to get my head around Elixir & Phoenix for some projects I've been wanting to do for years. Elixir and Phoenix are definitely a great fit for them! And thanks for all your hard work on these videos!!