{"id":23038854,"url":"https://github.com/kauefraga/cpp-commandline","last_synced_at":"2025-04-02T23:44:19.245Z","repository":{"id":179293693,"uuid":"662851380","full_name":"kauefraga/cpp-commandline","owner":"kauefraga","description":"🧶 A command line (CLI) library that will help you to build your command line applications with out of the box.","archived":false,"fork":false,"pushed_at":"2023-07-09T20:15:44.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T14:09:19.394Z","etag":null,"topics":["cli","command-line","commandline","cpp","parser"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kauefraga.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-07-06T03:00:23.000Z","updated_at":"2023-07-07T20:22:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"d2d567df-f797-42ed-ba96-a2fcbaee7607","html_url":"https://github.com/kauefraga/cpp-commandline","commit_stats":null,"previous_names":["kauefraga/commandline-parser"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kauefraga%2Fcpp-commandline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kauefraga%2Fcpp-commandline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kauefraga%2Fcpp-commandline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kauefraga%2Fcpp-commandline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kauefraga","download_url":"https://codeload.github.com/kauefraga/cpp-commandline/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246911490,"owners_count":20853654,"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","commandline","cpp","parser"],"created_at":"2024-12-15T18:25:43.254Z","updated_at":"2025-04-02T23:44:19.229Z","avatar_url":"https://github.com/kauefraga.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Command Line Library\n\n\u003e 🧶 A command line (CLI) library that will help you to build your command line applications with out of the box.\n\n### Features\n\n- Just copy the files `cli.h` and `cli.cpp` in your project and create your whole CLI with c++.\n- All the currently features are concisely in the class called `Cli`. \n- Easy to use and very simple to understand.\n- Well documented, therefore you don't need to crack your brain.\n- Written following [Google's c++ style guide](https://google.github.io/styleguide/cppguide.html).\n\n## ⬇️ Getting Started\n\n1. Download or clone the repository\n2. Copy the files `cli.h` and `cli.cpp` at `src` into your codebase\n3. See [usage](#usage) and [api](#api)\n\n```bash\n# (1)\ngit clone https://github.com/kauefraga/cpp-commandline.git\ncd cpp-commandline\n\n# (2)\ncp src/cli.h src/cli.cpp ../path/to/your/project\n```\n\nYou are welcome to open issues and pull requests!\n\n## Usage\n\nTo have access to the command line library features you need to include the files `src/cli.h` and `src/cli.cpp` in your source code.\n\nExample: include the library in your code, then use the class to parse the given arguments and print it out.\n\n```cpp\n// Input: main.exe \"Hiiii\" -number 23\n\n#include \"../path/to/cpp-commandline/cli.h\" // includes \u003cvector\u003e and \u003cstring\u003e\n\nint main(int argc, char* argv[]) {\n  // If there is only one argument or less, then print help\n  if (argc \u003c= 1) {\n    std::cout \u003c\u003c \"Usage: [name].exe [options]\" \u003c\u003c '\\n';\n    std::cout \u003c\u003c \"  -help (boolean)\" \u003c\u003c '\\n';\n      \n    return 1;\n  }\n\n  Cli cli(argc, argv, \"[name]\", \"[version]\");\n\n  // All the arguments\n  for (std::string argument : cli.arguments) {\n    if (argument == \"-help\") {\n      std::cout \u003c\u003c \"HERE IS YOUR HELP MY FRIEND\" \u003c\u003c '\\n';\n    }\n\n    std::cout \u003c\u003c argument \u003c\u003c '\\n';\n  }\n\n  std::cout \u003c\u003c \"----------------\" \u003c\u003c '\\n';\n\n  // Only the flags\n  for (std::string flag : cli.flags) {\n    std::cout \u003c\u003c flag \u003c\u003c '\\n';\n  }\n\n  return 0;\n}\n```\n\nExpected:\n\n```bash\n# main.exe -help\n\n\u003e path/to/the/executable/main.exe # the executable is part of the arguments\n\u003e HERE IS YOUR HELP MY FRIEND\n\u003e -help # By now, the flags are part of the arguments too\n\u003e ----------------\n\u003e -help\n```\n\n## API\n\n### Classes\n\n- `Cli` - It parses arguments, flags and store it.\n    - `Cli(int arguments_count, char* arguments_vector, string name, string version)` - The constructor takes the arguments count (`argc`), the arguments vector (`argv`), the application name, the version and stores it.\n    - Public methods: currently, there are only getters methods.\n    - Private methods: `parse_arguments` and `parse_flags`.\n    - Private properties: `m_arguments_count`, `m_arguments`, `m_flags`, `m_name` and `m_version`.\n\n### Util functions\n\n- `bool is_flag(string argument)` - Verify if there is a '-' at the initial position (0) of the argument.\n\nRead the doxygen documentation at [code](src/cli.h) too.\n\n## 🧻 Resources\n\nThese are the contents that i consume to develop this library:\n\n- [How to use c++ classes](https://www.learncpp.com/cpp-tutorial/class-code-and-header-files) - An awesome article about classes.\n- [How command line arguments work](https://www.learncpp.com/cpp-tutorial/command-line-arguments) - A wonderful content of command line arguments.\n- [Command Line Interface Guidelines](https://clig.dev) - An open-source guide to help you write better command-line programs.\n- [The API is inspired by Commander](https://www.npmjs.com/package/commander) - The complete solution for node.js command-line interfaces.\n- [C++ Colors](https://github.com/kauefraga/cpp-colors) - A collection of namespaces (ANSI escape code for colors) and functions that will help you to style and bring life to your console outputs. \n\n## 📝 License\n\nThis project is licensed under the MIT License - See the [LICENSE](https://github.com/kauefraga/cpp-commandline/blob/main/LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkauefraga%2Fcpp-commandline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkauefraga%2Fcpp-commandline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkauefraga%2Fcpp-commandline/lists"}