{"id":20246961,"url":"https://github.com/prdktntwcklr/embedded-cli","last_synced_at":"2026-05-10T18:42:51.946Z","repository":{"id":208083711,"uuid":"657840458","full_name":"prdktntwcklr/embedded-cli","owner":"prdktntwcklr","description":"A simple command-line interface for use in embedded systems.","archived":false,"fork":false,"pushed_at":"2024-05-05T04:37:24.000Z","size":55,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-14T02:12:57.585Z","etag":null,"topics":["cli","command-line","embedded","microcontroller","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Ovyl/embedded-cli","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prdktntwcklr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-24T01:48:39.000Z","updated_at":"2024-05-05T04:37:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"2bdb3256-d4e5-47f5-8d76-12d1d38219bd","html_url":"https://github.com/prdktntwcklr/embedded-cli","commit_stats":null,"previous_names":["prdktntwcklr/embedded-cli"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prdktntwcklr%2Fembedded-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prdktntwcklr%2Fembedded-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prdktntwcklr%2Fembedded-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prdktntwcklr%2Fembedded-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prdktntwcklr","download_url":"https://codeload.github.com/prdktntwcklr/embedded-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241692796,"owners_count":20004299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","command-line","embedded","microcontroller","unit-testing"],"created_at":"2024-11-14T09:34:24.497Z","updated_at":"2026-05-10T18:42:46.926Z","avatar_url":"https://github.com/prdktntwcklr.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cli-embedded\nA simple command-line interface for use in embedded systems. This useful tool\nallows a user to remotely invoke functions on their device by specifing commands\n(and parameters) over a byte stream protocol. Based on earlier work by\n[Sean Farrelly](https://github.com/FARLY7) and [Ovyl](https://github.com/Ovyl/).\n\n## Features\n* Remotely invoke functions on device.\n* Ability to process function parameters.\n* Statically allocated memory.\n\n## Introduction\nThis package contains files to implement a simple command-line interface.\nThe package includes cli.h, cli_defs.h and cli.c.\n\n## Integration details\n* Integrate cli.h, cli_defs.h and cli.c files into your project.\n* Include the cli.h header file in your code like below.\n\n```c\n#include \"cli.h\"\n```\n\n## File information\n* cli.h : This header file contains the definitions of the cli user API.\n* cli_defs.h : This header file contains some common defines, enums and structs.\n* cli.c : This source file contains the implementation of the CLI.\n\n## Supported interfaces\n* Typically, UART.\n* Any byte-stream based interface.\n\n## Integration Guide\n### Initialising the CLI\nTo correctly set up the CLI, the user must do four things:\n\n1. Create a table of commands which are to be accepted by the CLI, using the cmd_t structure.\n\n**Note**: Command functions must use the ```cli_status_t (*func)(int argc, char **argv)``` definition.\n```c\ncmd_t cmds[2] = {\n    {\n        .cmd = \"help\",\n        .func = help_func\n    },\n    {\n        .cmd = \"echo\",\n        .func = echo_func\n    }\n};\n```\n\n2. Place the cli_put() function within the devices interrupt handler responsible for receiving 1 byte over the communication protocol.\n ```c\n void UART_Rx_IrqHandler()\n {\n     char c = UART-\u003eRxData;\n     cli_put(\u0026cli, c);\n }\n ```\n\n3. Create an instance of the CLI handle structure, and fill in the required parameters.\n```c\nstatic uint8_t cli_buffer[256] = {0};\n\ncli_t cli = {\n    .println = user_uart_println,\n    .cmd_tbl = cmds,\n    .cmd_cnt = sizeof(cmds)\n};\n\ncli_status_t result = cli_init(\u0026cli, cli_buffer, sizeof(cli_buffer));\n\nif((result != CLI_OK)\n{\n    printf(\"CLI: Failed to initialise\");\n    return;\n}\n```\n\n4. Periodically call the ```cli_process()``` function in order to process incoming commands.\n```c\nwhile(1)\n{\n    char in = fgetc(stdin);\n    cli_put(\u0026cli, in);\n    cli_process(\u0026cli);\n}\n```\n\n## User Guide\nTo interface with the CLI, the user must open a communication stream on their chosen protocol (typically UART).\nThe default end-of-delimiter used by the application is '\\n', however this can be changed.\nThe user can invoke their functions by sending:\n```cmd \u003cparam\u003e\\n```\n* cmd, the name of the command\n* \\\u003cparam\\\u003e, first parameter (if required).\n\n## Function templates\n```c\ncli_status_t user_uart_println(char *string)\n{\n    /* For example.. */\n    if(HAL_UART_Transmit_IT(\u0026huart, string, strlen(string)) != HAL_OK)\n    {\n        return SLI_E_IO;\n    }\n\n    return SLI_OK;\n}\n\ncli_status_t help_func(int argc, char **argv)\n{\n    cli_status_t result = CLI_OK;\n\n    /* Code executed when 'help' is entered */\n\n    return result;\n}\n\ncli_status_t echo_func(int argc, char **argv)\n{\n    cli_status_t result = CLI_OK;\n\n    /* Code executed when 'echo' is entered */\n\n    return result;\n}\n```\n\n## Building the sample code\nOpening the project in VS Code with the\n[Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)\nenabled allows you to work directly from a Docker container with all required\npackages already installed. First, run the following command from the root\ndirectory:\n```\ncmake -B build/\n```\nThis will initialize the repo for CMake. Then build the project:\n```\ncmake --build build/\n```\nThis will generate the executable `cli_example` inside the `build` directory.\nThis can be run with the command:\n```\n./build/cli_example\n```\nYou should see the prompt `Welcome to the cli. Type 'help' to get a list of commands.`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprdktntwcklr%2Fembedded-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprdktntwcklr%2Fembedded-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprdktntwcklr%2Fembedded-cli/lists"}