I’m trying build a basic cli app for the purpose of learning.
Lets say we are making a basic cli for counting words of one or more txt documents
The requirement of my app is as listed:
- The program accepts as arguments a list of one or more file paths (e.g. ./wordcount file1.txt file2.txt …).
- The program also accepts input on stdin (e.g. cat file1.txt | ./wordcount).
First of all here is my current working example of a cli escript app. https://gist.github.com/joshchernoff/4a6678a555f61edc771649576c344f58
One of the things not listed that bothered me was the app would just hang if no input via args or sdtin was given.
I understand the app was just waiting for input from the terminal and if I typed it would read via IO.read, but I would think that it would be more helpful that I gave an error if no input was given and then just stop the app.
I didn’t realize that it’s a common thing for stdio to just wait there.
I guess at this point I’m at a loss for common bast practices.
- should the app just hang expecting some form of stdin?
- should the app be smart and see nothing is happening and report according?
- should I have an explicit flag that denotes how I want to explicitly use the app?
Sorry for such a open ended question, its just that this was also a part of a tech challenge for a job interview that I completely tanked today. Not feeling very good about myself right now. I wish I had a better understanding of standards and this type of utility apps feels very foreign to me as primarily a web developer just starting to make phoenix apps.