DEV Community

Matt Tran
Matt Tran

Posted on

How to Create a CLI App in 5 Steps

In Phase 3 of my learning journey at Flatiron, we began to learn about Python. As we approach the end of this phase, our project of the phase was to create a CLI app. Our group decided to make a Fitness Tracker CLI, and here's a five-step skeleton of how we did it!

Step 1 - Plan
Before beginning to plan, we set clear goals for what we wanted to accomplish. We value the gym, so we wanted to create an app that allowed users to add or remove exercises and workouts.

Step 2 - Data Models
After deciding what we wanted our app to do, we needed to decide what classes we would add and what their relationships would be. We agreed on our project's three classes (exercise, workout, and user). For their relationships, we wanted "workout" to have a one-to-many relationship with "exercise" and "workout" to belong to a user.

Step 3 - ORM
During this step, we used SQLAlchemy to interact with our database. During this step, we created modules for the ORM methods we wanted.

STEP 4 - CLI
After setting up SQLAlchemy and our ORM, we focused on creating the CLI. To help with this process, we used Click to generate the command-line interface (CLI). At this point, we also defined our commands for the CLI.

Step 5 - Implementing CLI Commands
Here, we wrote functions for our CLI commands and added information for error messages. We also used this step to implement PrettyTable, Figlet, and animations as embellishments to our CLI app to give it some more pizzazz.

Overall, it was a fun experience to create our first CLI app!

Top comments (0)