Giter Club home page Giter Club logo

mycli's Introduction

MyCLI

An embedded command line interface (CLI) that you can embed into your C/C++ code

Quick start

This is a quick start guide to getting MyCLI up and running fast.

This will assume you have your own main.c in a directory that we will work off.

The quick start will be assume you have the following directory structure:

QuickStart/main.c
QuickStart/MyCLI/src/CLI.h
QuickStart/MyCLI/src/Example_CLI_Options.h
QuickStart/MyCLI/src/Full/CLI.c

Step 1

Copy QuickStart/MyCLI/src/Example_CLI_Options.h to QuickStart/CLI_Options.h

Step 2

Add the following functions to your main.c (and fill them in with working code):

Function Description
bool HAL_CLI_IsCharAvailable(void) Returns true when HAL_CLI_GetChar() will return a char
char HAL_CLI_GetChar(void) Gets the next char from your input stream
void HAL_CLI_PutChar(char c) Sends a char out your output stream
uint32_t HAL_CLI_GetMilliSecCounter(void) Returns the number of milliseconds. This can just return 0

So for example you can set these functions up to talk on your UART.

Step 3

Add a structure for your commands to your main.c file.

const struct CLICommand g_CLICmds[]=
{
    {"MyCommand","My one line help string",MyCommandFn},
};

Step 4

Add your command functions (don't forget to add a prototype above g_CLICmds).

void MyCommandFn(int argc,const char **argv)
{
    printf("Hello MyCommand!\n");
}

Step 5

Init the prompt in main()

    struct CLIHandle *Prompt;
    char LineBuff[100];
    char HistoryBuff[100];

    Prompt=CLI_GetHandle();
    CLI_InitPrompt(Prompt);
    CLI_SetLineBuffer(Prompt,LineBuff,sizeof(LineBuff));
    CLI_SetHistoryBuffer(Prompt,HistoryBuff,sizeof(HistoryBuff));

Step 6

Add CLI_RunCmdPrompt() to your main while loop.

    CLI_DrawPrompt(Prompt);
    while(1)
        CLI_RunCmdPrompt(Prompt);

Step 7

Compile. gcc -I MyCLI/src -I . MyCLI/src/Full/CLI.c main.c

See also

Check out Examples/Basic for a Linux version that talks on stdio.

mycli's People

Contributors

thebeef avatar

Stargazers

 avatar Şeyma Görücü avatar  avatar

Watchers

 avatar

mycli's Issues

Add auto complete

Add a TAB auto complete system for commands and args (using help system).

Command groups

Add groups of command instead of using the global list of available commands. Useful for hiding command from the help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.