Supporting terminal input/output
In the previous chapter, we left off with our Processor
type having a def process(input : String) : String
method that handles transforming the input string, processing it via jq, and then transforming and returning the output data. We then call this method with static input. However, a CLI application is not very useful if it needs to be recompiled every time you want to change the input data.
The more proper way to handle this is by leveraging terminal-based IO, namely, Standard In (STDIN), Standard Out (STDOUT), and Standard Error (STDERR). These will allow us to consume data, output data, and output errors, respectively. In fact, you have already been using STDOUT without even knowing it! The Crystal method puts
writes the content passed to it to STDOUT, followed by a newline. STDOUT's type inherits from the abstract IO type, which also defines a puts
method on the IO instance. Basically, this allows you to do the same thing as the top-level...