Simple Interfaces

The beauty of command-line applications is that they all have the same simple interface, as shown in Figure 16, Command-line applications all use the same simple interface. They can read from standard input (STDIN) and write to standard output (STDOUT). When something goes wrong, they sometimes write to standard error (STDERR). In addition to using those three streams, command-line applications can accept arguments on the command line, which in Ruby end up in the ARGV constant. Consider the following command:

 
cp foo.txt bar.txt

Here, the two command-line arguments foo.txt and bar.txt are passed to the cp command-line application.

When a command-line application is done and exits, it reports how the execution went with an exit status. On Linux and OS X, the exit status is available in the shell variable named $?. On Windows, it’s available in %ERRORLEVEL%. A nonzero exit status is used to indicate that something went wrong.

images/cli-simple-interface.png

Figure 16. Command-line applications all use the same simple interface.

Command-line applications can be written in any programming language, and they can be combined with pipes, like Lego, to perform more advanced tasks.

Seen from the outside, all command-line applications are the same. The only way to interact with them is via streams and command-line arguments. This also means that as far as Cucumber is concerned, the approach for interacting with a command-line application is the same regardless of what the application does or what programming language it’s written in. Because the high-level interaction is the same for all command-line applications, there is no need to reinvent the wheel every time we want to test a new command-line application. Aruba has everything we need.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.221.144