Blink DB Documentation v1.0.0
Blink DB Documentation
Loading...
Searching...
No Matches
cli.cpp File Reference

A simple command-line program that processes user input. More...

#include "command_parser.hpp"
#include <iostream>
#include <signal.h>
#include <string>

Functions

std::string getHeader ()
 Returns the prompt header string for the user input.
void handle_sigint (int)
 Signal handler for SIGINT (Ctrl + C) interrupt.
int main (int argc, char *argv[])
 Main function that processes user input.

Detailed Description

A simple command-line program that processes user input.

This program provides a command-line interface where the user can input commands. It uses a CommandParser object to process each line of input. The program is designed to handle SIGINT (Ctrl + C) gracefully and provides an interactive prompt for the user to enter commands.

When the user presses Ctrl + C (SIGINT), the program will display a message reminding the user to exit using the "exit" command or Ctrl + D. The program clears the screen on startup and repeatedly prompts for user input until the program is terminated.

Note
The command-line input is passed to a CommandParser class for parsing and processing.
Author
Sai Kasyap Jannabhatla
Date
March 2025
Version
1.0

Function Documentation

◆ getHeader()

std::string getHeader ( )

Returns the prompt header string for the user input.

This function provides a string that is displayed as a prompt to the user when accepting input.

Returns
A string representing the prompt header (e.g., "User> ").

◆ handle_sigint()

void handle_sigint ( int )

Signal handler for SIGINT (Ctrl + C) interrupt.

This function is triggered when the user presses Ctrl + C. It displays a message prompting the user to use the exit command or Ctrl + D to exit the program.

Parameters
signumThe signal number (not used in this case).

◆ main()

int main ( int argc,
char * argv[] )

Main function that processes user input.

This function initializes signal handling, clears the terminal screen, and enters a loop where it continually prompts the user for input. The input is passed to a CommandParser instance, which processes the command.

Parameters
argcThe number of command-line arguments (not used in this case).
argvThe command-line arguments (not used in this case).
Returns
An integer indicating the status of the program execution (0 for success).