Rey T
2 min readFeb 8, 2021

--

CLI Application: The Set up

For our first portfolio project, we were asked to create a CLI application that requires several steps for a user to be able to get data. In other words, the user makes a selection & then given two options of how to obtain the data. Students could either use the scraping method or access the websites’ API (Application Programming interface). I chose option two, accessing the websites’ API as the method for retrieving the data.

The setup included creating various files, executable and environment file; and adding items to the gemfile. Within the environment file, it was necessary to require all files “bundling them” so that all of the files are able to communicate with each other.

Environment.rb:

require_relative”./countries_cli/version”

require ‘bundler’

Bundler.require

require_relative “./countries_cli/api”

require_relative “./countries_cli/cli”

require_relative “./countries_cli/country”

The executable file is created within the bin folder and is known as the main entrance to the application. An important aspect of this file is the addition of the shebang line: #!/usr/bin/env ruby. The shebang line is needed because the executable file does not contain .rb therefore, the shebang line informs the environment file that ruby will be used in the executable file. Also, this line allows the excutable file to operate in different areas, not just ruby.

Excutable File:

#!/usr/bin/env ruby

require_relative ‘../lib/environment.rb’

The setup was a crucial part of this program. Each file had its own duties and responsibilities. The environment file’s job is to bundle all requirements into one file which is then passed to the executable file because it is the entry to the application and will initiate the other classes involved in the program. Each file has a task and it is important that the tasks are completed in order to have a successful application.

--

--