My First Ever CLI Project

Jonathan Zavala
4 min readJan 10, 2021

This is the first ever software engineering project I have ever done. I didn’t know what to expect or if I could even do it. I felt overwhelmed with the thought of building something almost from scratch. As I was feeling all these emotions I knew there was only one way to get rid of them, and that was to tackle it head on. Write the code, make the mistakes, read the errors, then after all the errors and mistakes, learn from them. Let me take you through of few of my mistakes, so maybe you learn from mine.

My Build

My project was a CLI (command line interface) that used an API (application program interface) from the website that had all the characters from the tv show “Breaking Bad”. This website provided me with the a lot of information on each character. I wanted the users of my application to be able to select a character’s name and learn more about them. Therefore the project had to be “two level deep” meaning the user is given a menu option that takes them to the list of characters (level 1) then after the user selects a character the application returns the character’s information (level 2). I was able to create the level and allow the user to interact with them but I ran into two problems.

Problem #1

When the user would input an invalid response on the list of character menu of the application. The app would break, I looked over it because I was just happy I got the original menu working and a valid input of the character list working. Lesson #1 don’t get too excited and over look some mistakes. This is what my code looked like before I fixed the error.

 selection = user_input
character = Characters.find_character(selection)
character_details(character)
end

This code allowed my users to input a character’s name and return that characters information. The reason this code was able to work was because of the code I wrote in my Characters class in the breaking_bad_cli folder.

def self.find_character(character_name) self.all.find do |character| character.name == character_nameend

This code is telling my program to search all of the character’s names till the name that the user input into the program matches the one on the list and then returns it to the previous code and prints the character’s information. But that all it did. If the user typed something other that the character’s name the program broke. Here is the code after I fixed the error.

selection = user_inputif character = Characters.find_character(selection) character_details(character)elsif selection == 'exit' goodbyeelse invalidend

With this code if the user inputs the name correctly it still returns the information it also accepts the users input if they want to exit out the program by allowing the to enter “exit” and it will return the goodbye method. Then anything else that the user were to put in would be invalid which would return the invalid method.

Correct code result:

Problem #2

When the user would type in ‘exit’ the puts message from the goodbye method would be printed, but the user would still be in the application. This is what the code looked like before.

def goodbye
puts "It was nice meeting you, come back anytime!"
end

I did some research on how to exit my user out of an application and the first link that popped up had what I was looking for. I should have thought of it before but for the life of me I couldn’t (I think I had been looking at the screen too long, take breaks) but once I seen the answer it was obvious. Let me show you.

def goodbye puts "It was nice meeting you , come back anytime!" exitend

How could I have possibly not thought of that after using binding pry through out all my coding exercises. It was just one of those things over looking what was right in front of you either from fatigue or getting ahead of yourself.

Correct code result:

Hopefully some of my mistakes were helpful to others because I know they were for me. My cohort lead always says “errors are good” and for every error there is an opportunity to learn, to get better, it’s all part of the journey.

--

--