First CLI Project

Muhammad Danyal Mahdi
4 min readMar 19, 2021

It has been 2 months in Flatiron School Software Engineering Bootcamp and now it's time to submit a Command Line Interface Project also referred to as the Module One Project. The material we have covered in the last 2 months was very overwhelming at first especially for a person like me, with no CS (Computer Science) background. My coach along with online instructors helped me a lot to grasp everything to bits.

I had done many labs including the Tic Tac Toe and Music Library which totally helped me learn to build a CLI app from scratch but this idea of working on a project alone was a bit intimidating at first. When I went over the Readme.MD of the project, It went over my head. I thought I would not be able to make it and even if I do, it would not be on time. I hate to say that it caused me anxiety, a very bad one but Flatiron does not let its students dive into a loop of anxiety.

It took me time to realize that I have already done everything before, instructed in that Readme. My cohort instructor helped a lot, he showed us demo projects plus few labs that could help us get an idea of how a CLI project looks. Now it was time to build one on my own.

I divided my project into three steps, pre-structure, structure, and executing. Pre-structuring was easy but building and executing is what made me bang my head into a wall,(just kidding). As far as the first phase was concerned it was similar to making a To-Do list. First of all, I went over the instructions in the Readme file and tried to figure out Project requirements. It asked us to build a CLI app with one-level deep information that interacts with the user. In my Notes.MD file in the vs code, I had written all my major points that I have to focus on while building this application.

For my project at first, I chose to display the best school districts in NYC through scraping a webpage but it was hard to figure out which page is scrapeable. I got stuck on this for a while and later chose to use an open API instead of scraping. I could not find an API for school districts so I changed it with the idea of displaying the Covid-19 database using an API. Although I later found out that there is a tool to check if a website is scrapeable but it was too late for me to go back. According to the program, I wanted to ask a user to log in with an existing username or create one if they do not have one. It will later give them the list of the affected countries and ask them about which country they want details about and then according to their input, it will give them details. I also added error handling, in which it will give them an error message if an input is not valid, allow them to go back to the menu, or press exit to exit the app.

In the structure phase, I started off by making a gem, although it was not required as I could I have done it by doing *gitinit but making a gem, does everything for you by making all the files necessary to work, including readme, lib, bin, code of conduct, gem file, rake file, and license.

In the terminal, it should look like this:

bundler gem name_of_your_project

I had to require all the gems in the gems and environment file that I needed for my project and also add development dependencies of those gems too. In my case it looked like this:

require ‘pry’

require ‘HTTParty’

require ‘colorize’

You can also use Nokogiri, NET/HTTP, and open-URI but in my case, I only used HTTParty to extract data out of my API. I used colorize gem to add colors to my CLI application and make it look attractive, you can also use the ASCII art tool to add a more realistic look to it. *Note: If you have an API key for your data then you have to require dotenv/load gem to hide the API key from GitHub. You can do it by making a .env file inside your vs code, paste the API key there and then put that .env file inside the gitignore file. You might have to make a Gitignore file if you do not have but if you make a gem for your project then it automatically makes one for you.

Later you have to make a CLI, project_name, and API/scraper file inside the lib folder in which you write all of your code. CLI.RB is the file used for the user interface, in simple language, it runs your code for you and displays your CLI app on the terminal. It all comes with proper management and planning of methods, inside each file plus requiring all of them inside the environment file. Just for an idea, my API.RB file looked like this:

@response = HTTParty.get(URL)

CLI project is a demo of what kind of stuff we would have to deal with in the future. It helps us to build in ourselves the basic skills of a developer. It looked a bit intimidating at first but once I went through the proper steps and a lot of google searches, it became very easy to handle. I love my CLI app and once I become more familiar with programming, I would definitely be able to add some more cool stuff to it.

--

--