Newsletter # 10 - Command-line argument parsing using Swift Package Manager's SPMUtility module Nov 22 2019

Hello,

Have you ever wondered why the home directory is mapped to ~? Or if you use vi, why use the letters H, J, K, and L to move?

These types of questions are the ones that keep me up at night. Not really :D, but I find them interesting.

I found answers to many of these questions in this article:

https://dave.cheney.net/2017/08/21/the-here-is-key

The author explains how the "Lear Siegler ADM-3A terminal" influenced so much of our current computing. Check the keyboard for the terminal. See how most of the keys match some of the "conventions" we have today. It's a fun read about computing history.

I wonder what changes we are creating now with our work. Imagine that something you are working on will influence the history of computing, that's exciting :)

Well, you are probably already building tools that make your user's life better. If that is the case, you might find this week's article useful (I hope you enjoyed that smooth segue into this week's post :) ).

This week's post is about using the Swift Package Manager's SPMUtility module to do the argument parsing of your command-line tools. I think it's the perfect example of good design, kudos to the Swift Package Manager(SPM) team. The module is independent enough that you can pull it to your project without having to change the way your tool behaves. It's a good model to follow. We should strive to write code that is "replaceable". We should build our code so it can be used and with time be refactored or replaced completely without breaking the whole codebase. Here is the link to the article if you want to check it out:

https://rderik.com/blog/command-line-argument-parsing-using-swift-package-manager-s/

Ok, that's it for this week. Enjoy your weekend.

Derik

Tip of the Week

Alright, this time I'll post a tip that a dear friend of mine reminded me about. Have you ever wanted to switch to one directory to check a file then go back to the previous directory? Well, that's easy you can use cd - to accomplish that. For example:

1
2
3
4
/Users/derik/Desktop  $ cd ~/Documents
/Users/derik/Documents $ # run any command you want and head back to the previous directory
/User/derik/Document  $ cd -
/User/derik/Desktop  $  

Alright, but that seldom happens. What actually happens is that we go to the new directory, and then we see that we have to dive deeper into another path or go to a different directory, you get the idea.

In that case, let me introduce you to pushd and popd :). We have access to a stack where we can push the current directory and switch to another directory and then we can just pop, and we'll be back to the directory we pushed from. Very handy! Let me show you an example:

1
2
3
4
5
/Users/derik/Desktop  $ pushd /usr/local/
/usr/local       $ cd shared
/usr/local/bin     $ cd ../etc/httpd
usr/local/etc/httpd  $ popd
/User/derik/Desktop  $ # :)

You can do as many "push"s as you need, very useful.

Thanks again to my friend for the reminder. I hope you find it useful.


** If you want to check what else I'm currently doing, be sure to follow me on twitter @rderik or subscribe to the newsletter. If you want to send me a direct message, you can send it to derik@rderik.com.