Home

Awesome

no-cli

GitHub

Build Status Codecov C99

Cheesy command line interpreter designed for tiny memory-constrained systems. Minimal dependencies: just string.h.

Features

Possible future features, if I need them:

Usage

Example

See test/example.c for an example that runs on host.

You can try the example by building it and running it:

# build
❯ make -f test/Makefile
Compiling nocli.c
Compiling test/example.c
Linking build/example/example

# run
❯ ./build/example/example

nocli$ help

?
help
count-args      print number of args passed
change-prompt   set prompt to new string
nocli$ count-args 1 2 3
Arg count: 3

nocli$

Integration

API is documented in nocli.h. There's only two functions used:

  1. initialize the library: void Nocli_Init(struct Nocli *nocli);

    this includes a callback for outputting data and the table of commands.

  2. pass any amount of data: void Nocli_Feed(struct Nocli *nocli, const char *input, size_t length);

    commands are executed within this function, so be sure to call it in a safe context

libfuzzer crashes

Run libfuzzer with make -f test/Makefile fuzz; it will run continuously until a crash occurs (AddressSanitizer and UndefinedBehaviorSanitizer are enabled on the fuzz build)

Crashes that libfuzzer finds are saved in test/corpus, which are run through the library in ci to catch regressions.

License

WTFPL (http://www.wtfpl.net/) or public domain, whichever you prefer.


Alternatives!

This library conflates two operations:

There are a LOT of alternatives. Here's some commonly used ones:

Line editing

Argument parsing