{"id":13780258,"url":"https://github.com/PelionIoT/mbed-client-cli","last_synced_at":"2025-05-11T13:31:51.666Z","repository":{"id":45877228,"uuid":"41283271","full_name":"PelionIoT/mbed-client-cli","owner":"PelionIoT","description":"Command Line Interface library for device","archived":false,"fork":false,"pushed_at":"2021-11-30T13:10:43.000Z","size":345,"stargazers_count":16,"open_issues_count":4,"forks_count":13,"subscribers_count":120,"default_branch":"master","last_synced_at":"2024-05-18T21:40:29.908Z","etag":null,"topics":["cli","interpreter","mbed-client-cli"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PelionIoT.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}},"created_at":"2015-08-24T05:10:00.000Z","updated_at":"2023-12-06T14:26:25.000Z","dependencies_parsed_at":"2022-07-22T20:22:17.228Z","dependency_job_id":null,"html_url":"https://github.com/PelionIoT/mbed-client-cli","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PelionIoT%2Fmbed-client-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PelionIoT%2Fmbed-client-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PelionIoT%2Fmbed-client-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PelionIoT%2Fmbed-client-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PelionIoT","download_url":"https://codeload.github.com/PelionIoT/mbed-client-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224713624,"owners_count":17357247,"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","interpreter","mbed-client-cli"],"created_at":"2024-08-03T18:01:13.861Z","updated_at":"2024-11-17T15:31:02.543Z","avatar_url":"https://github.com/PelionIoT.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# mbed-client-cli\n\nThis is the Command Line Library for a CLI application. It uses only ansi C features so it is portable and works in Mbed OS, linux and windows.\n\n## Features\n\nLibrary provides features such:\n\n* Adding commands to the interpreter.\n* Deleting commands from the interpreter.\n* Executing commands.\n* Adding command aliases to the interpreter.\n* Searching command arguments.\n* implements several VT100/VT220 features, e.g.\n  * move cursor left/right (or skipping word by pressing alt+left/right)\n  * delete characters\n  * CTRL+W to remove previous word\n  * browse command history by pressing up/down\n* implements basic commands, e.g.\n  * echo\n  * help\n  * (un)set\n  * alias\n  * history\n  * true/false\n  * clear\n\n## API\n\nCommand Line Library basic API's is described in the snipplet below:\n\n```c++\n// if thread safety for CLI terminal output is needed\n// configure output mutex wait cb before initialization so it's available immediately\ncmd_set_mutex_wait_func( (func)(void) );\n// configure output mutex release cb before initialization so it's available immediately\ncmd_set_mutex_wait_func( (func)(void) );\n// initialize cmdline with print function\ncmd_init( (func)(const char* fmt, va_list ap) );\n// configure ready cb\ncmd_set_ready_cb( (func)(int retcode)  );\n// register command for library\ncmd_add( \u003ccommand\u003e, (int func)(int argc, char *argv[]), \u003chelp\u003e, \u003cman\u003e);\n//execute some existing commands\ncmd_exe( \u003ccommand\u003e );\n```\n\nFull API is described [here](mbed-client-cli/ns_cmdline.h)\n\n### Configuration\n\nFollowing defines can be used to configure defaults:\n\n|define|type|default value|description|\n|------|----|-------------|-----------|\n|`MBED_CONF_CMDLINE_USE_MINIMUM_SET`|bool|false|Use preconfigured minimum build. See more details from below|\n|`MBED_CONF_CMDLINE_ENABLE_ALIASES`|bool|true|Enable aliases|\n|`MBED_CONF_CMDLINE_USE_DUMMY_SET_ECHO_COMMANDS`|bool|true|Enable dummy `set` and `echo` commands|\n|`MBED_CONF_CMDLINE_INIT_AUTOMATION_MODE`|bool|false|Enable automation mode during initalize phase|\n|`MBED_CONF_CMDLINE_ENABLE_ESCAPE_HANDLING`|bool|true|Enable escape handling|\n|`MBED_CONF_CMDLINE_ENABLE_OPERATORS`|bool|true|Enable operators. E.g. `echo abc \u0026\u0026 echo def`|\n|`MBED_CONF_CMDLINE_ENABLE_INTERNAL_COMMANDS`|bool|true|Enable internal commands. E.g. `echo`|\n|`MBED_CONF_CMDLINE_ENABLE_INTERNAL_VARIABLES`|bool|true|Enable internal variables|\n|`MBED_CONF_CMDLINE_BOOT_MESSAGE`|C string|`ARM Ltd\\r\\n`|default boot message|\n|`MBED_CONF_CMDLINE_MAX_LINE_LENGTH`|int|2000|maximum command line length|\n|`MBED_CONF_CMDLINE_ARGS_MAX_COUNT`|int|30|maximum count of command arguments|\n|`MBED_CONF_CMDLINE_ENABLE_HISTORY`|bool|true|Enable command history. browsable using key up/down|\n|`MBED_CONF_CMDLINE_HISTORY_MAX_COUNT`|int|32|maximum history size|\n|`MBED_CONF_CMDLINE_INCLUDE_MAN`|bool|true|Include man pages|\n|`MBED_CONF_CMDLINE_ENABLE_INTERNAL_TRACES`|bool|false|Enable cli internal traces|\n|`MBED_CONF_CMDLINE_ENABLE_DEEP_INTERNAL_TRACES`|bool|false|Enable cli deep internal traces|\n\n\n#### Minimize footprint\n\nTo reduce required flash and RAM usage there is pre-defined profile which can be enabled by using precompiler variable:\n\n`MBED_CONF_CMDLINE_USE_MINIMUM_SET=1`\n\nThis switch off most of features and reduce buffer sizes. Below is whole configueration:\n\n|define|value|\n|------|----|\n|`MBED_CONF_CMDLINE_ENABLE_ALIASES`|false|\n|`MBED_CONF_CMDLINE_USE_DUMMY_SET_ECHO_COMMANDS`|false|\n|`MBED_CONF_CMDLINE_INIT_AUTOMATION_MODE`|false|\n|`MBED_CONF_CMDLINE_ENABLE_ESCAPE_HANDLING`|false|\n|`MBED_CONF_CMDLINE_ENABLE_OPERATORS`|false|\n|`MBED_CONF_CMDLINE_ENABLE_INTERNAL_COMMANDS`|false|\n|`MBED_CONF_CMDLINE_ENABLE_INTERNAL_VARIABLES`|false|\n|`MBED_CONF_CMDLINE_MAX_LINE_LENGTH`|100|\n|`MBED_CONF_CMDLINE_ARGS_MAX_COUNT`|10|\n|`MBED_CONF_CMDLINE_ENABLE_HISTORY`|false|\n|`MBED_CONF_CMDLINE_INCLUDE_MAN`|false|\n\n### Pre defines return codes\n\neach command should return some of pre-defines return codes.\nThese codes are reserved and used in test tools.\n\n|define|description|\n|------|-----------|\n|`CMDLINE_RETCODE_COMMAND_BUSY`|Command Busy|\n|`CMDLINE_RETCODE_EXCUTING_CONTINUE`|Execution continue in background|\n|`CMDLINE_RETCODE_SUCCESS`|Execution Success|\n|`CMDLINE_RETCODE_FAIL`|Execution Fail|\n|`CMDLINE_RETCODE_INVALID_PARAMETERS`|Command parameters was incorrect|\n|`CMDLINE_RETCODE_COMMAND_NOT_IMPLEMENTED`|Command not implemented|\n|`CMDLINE_RETCODE_COMMAND_CB_MISSING`|Command callback function missing|\n|`CMDLINE_RETCODE_COMMAND_NOT_FOUND`|Command not found|\n\n## Tracing\n\nCommand Line Library has trace messages, which are disabled by default.\n`MBED_CONF_CMDLINE_ENABLE_INTERNAL_TRACES` flag if defined, enables all the trace prints for debugging.\n\n## Usage example\n\nSee full examples [here](example).\n\n###\nAdding new commands to the Command Line Library and executing the commands:\n\n```c++\n//example print function\nvoid myprint(const char* fmt, va_list ap){ vprintf(fmt, ap); }\n\n// ready cb, calls next command to be executed\nvoid cmd_ready_cb(int retcode) { cmd_next( retcode ); }\n\n// dummy command with some option\nint cmd_dummy(int argc, char *argv[]){\n  if( cmd_has_option(argc, argv, \"o\") ) {\n    cmd_printf(\"This is o option\");\n  } else {\n        return CMDLINE_RETCODE_INVALID_PARAMETERS;\n  }\n  return CMDLINE_RETCODE_SUCCESS;\n}\n\n// timer cb (pseudo-timer-code)\nvoid timer_ready_cb(void) {\n   cmd_ready(CMDLINE_RETCODE_SUCCESS);\n}\n\n// long command, that needs for example some events to complete the command execution\nint cmd_long(int argc, char *argv[] ) {\n   timer_start( 5000, timer_ready_cb ); //pseudo timer code\n   return CMDLINE_RETCODE_EXCUTING_CONTINUE;\n}\nvoid main(void) {\n   cmd_init( \u0026myprint );              // initialize cmdline with print function\n   cmd_set_ready_cb( cmd_ready_cb );  // configure ready cb\n   cmd_add(\"dummy\", cmd_dummy, 0, 0); // add one dummy command\n   cmd_add(\"long\", cmd_long, 0, 0);   // add one dummy command\n   //execute dummy and long commands\n   cmd_exe( \"dummy;long\" );\n}\n```\n\n## Thread safety\nThe CLI library is not thread safe, but the CLI terminal output can be locked against other\noutput streams, for example if both traces and CLI output are using serial out.\n\nThread safety example for Mbed OS is available [here](example/Mbed-OS/main.cpp).\n\n\n## Unit tests\n\nUnit tests are available in the `./test` folder. To run the unit tests in linux environment:\n```\ncd test\n./run_unit_tests.sh\n```\n\nUnit tests xml output will be generated to folder: `test/build`.\nCode coverage report can be found from: `./test/build/html/coverage_index.html`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPelionIoT%2Fmbed-client-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPelionIoT%2Fmbed-client-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPelionIoT%2Fmbed-client-cli/lists"}