Contents

Department Manager

Department Manager

A Command Line Interface program to manage the employees of different departments in a company. Simple project for understanding and practicing writing Command Line Interface Programs with intuitive commands.

Repository

Introduction

This is an simple personal project that I tackled because I was feeling like writing a somewhat simple CLI program. The idea was to write a program to manage employees of a company, organized by departments. At first, the idea was to write something similar to a Terminal User Interface, in which the user enters something reminiscent of an interactive menu. In which the user would read the available options, alas, “1. List Employees. 2. Add New Employee” and so on; then the user would input the desired option and so on… After a while I realized this approach, although doable and viable, was somewhat clunky and reminded me too much of school projects. So I decided to take it up a notch, at least slightly.

Implementing a simple CLI program implies understanding about Command Line Arguments and using a method to store data. For the sake of convenience and brevity, I decided to use simple CSV files. The result is a simple interface controlled entirely by command line arguments. This however ends up being very similar to a functional API in esscence. Of course, a production API would take many approaches to improve performance, reliability and accessibility, as well as maybe using other methods for storing data, most likely some kind of database, but in the end, the experience is similar and the learning bridge has been greatly reduced.

Installation

1
2
3
git clone https://github.com/UberChili/departments.git
cd departments
cargo build --release

Then you can run the executable via:

1
./target/release/departments

Or you can install globally so you can run it from anywhere:

1
cargo install --path .

Usage

This is a command line interface program, you do everything giving arguments to the program. Display the help dialog by doing:

1
departments --help

The available options are:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Options:
  -p, --path <PATH>              file_path
  -l, --list                     List employees from department
  -f, --find <FIND>              Find an employee by name
      --add                      Add a new employee
  -d, --department <DEPARTMENT>  Department of the employee
  -n, --name <NAME>              Name of the employee
  -a, --age <AGE>                Age of the employee
  -s, --salary <SALARY>          Salary of the employee
  -h, --help                     Print help
  -V, --version                  Print version

Listing employees

You can list employees like so:

1
departments --list

Or you can search employees by department name by doing:

1
departments --list -p <DEPARTMENT>

This will list all employees who are in the specified department.

Finding an employee

You can search for a specific employee like so:

1
departments --find -n <NAME>

This will list all employees with the specified name. This function can be improved by modifying the CSV structure and allowing full names in different fields, so that we could search for names or last names. But for now I think the example is sufficient.

Adding a new employee

You can add a new employee like so:

1
departments --add -d <DEPARTMENT> -n <NAME> -a <AGE> -s <SALARY>

Final thoughts

This project can be further worked upon. As mentioned above, I can improve the employee finding functions in order to be able to make more specialized searches. I also thought about turning this into a full TUI (Terminal User Interface). A remove employee function could also be useful, and so on and so forth, but I think this project is sufficient as a good starting example.