/basic-cli-repl

A basic command line app REPL demo

Primary LanguageC++Creative Commons Zero v1.0 UniversalCC0-1.0

A basic command line app with REPL using the cli11 library

Build Status

This project add the REPL (Read Evaluate Print Loop) functionality to the basic cli app demo. Extended notes on the concepts explored are discussed here.

The app demonstrates among other concepts a simple sentence level parsing.

What does the app do?

The app simulates a fictitious zoo which has only CATs, DOGs and PENGUINs!
REPL mode: This is activated when the app is executed without any flag or option i.e. $ app. It drops to the app's REPL console <app> _

  • <app> help(): shows a brief description of the app.
  • <app> list(): lists the available animals and possible actions/operations.
  • <app> cat walk: issues a command that an animal: cat should perform an action: walk.
  • <app> exit(): will exit the app.

Non-REPL mode: when you add a flag or option

  • list the available animals: $ app -l
  • list all possible operations/actions by an animal: $ app -l -a "cat"
  • Make an animal perform an action: $ app -a "cat" -o "talk"
  • Show app version: $ app --version
  • Show help: $ app --help
  • Pass in a file of animal and action: $ app -i data.txt OR $ app data.txt
    sample content of data.txt:
    cat walk
    dog talk
    penguin swim
    

I have only utilised the basic functionalities of the cli11 library. It is quite powerful, helping to lift the boilerplate of handling command line args. I have used the LLVM's command line tool, but I prefer the cli11 library to it. The only downside is that is not llvm stuff, which matters if you plan to upstream into llvm.

The Project also illustrates very basic stuffs like

Try it out

Just clone and to build run this script: . ./run.sh
To build and run in docker use this: . ./docker-run.sh
The name is app, see above for sample usage. REPL mode: $ app. Non-REPL mode: $./app --help