{"id":16721130,"url":"https://github.com/khalyomede/command-builder","last_synced_at":"2025-03-15T12:23:18.807Z","repository":{"id":57006160,"uuid":"449447213","full_name":"khalyomede/command-builder","owner":"khalyomede","description":"Create executable strings using a fluent API.","archived":false,"fork":false,"pushed_at":"2022-01-20T20:19:11.000Z","size":50,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T03:47:37.422Z","etag":null,"topics":["builder","command","executable","fluent-api"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/khalyomede/command-builder","language":"PHP","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/khalyomede.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-01-18T21:05:08.000Z","updated_at":"2022-01-26T16:54:58.000Z","dependencies_parsed_at":"2022-08-21T14:30:43.512Z","dependency_job_id":null,"html_url":"https://github.com/khalyomede/command-builder","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fcommand-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fcommand-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fcommand-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fcommand-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khalyomede","download_url":"https://codeload.github.com/khalyomede/command-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243681047,"owners_count":20330155,"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":["builder","command","executable","fluent-api"],"created_at":"2024-10-12T22:28:56.589Z","updated_at":"2025-03-15T12:23:18.788Z","avatar_url":"https://github.com/khalyomede.png","language":"PHP","readme":"# command-builder\n\nA PHP class to build executable with using fluent API.\n\n## Summary\n\n- [About](#about)\n- [Features](#featues)\n- [Installation](#installation)\n- [Examples](#examples)\n- [Compatibility table](#compatibility-table)\n- [Tests](#tests)\n\n## About\n\nI need to have a fluent way to call my executable. I did not found any other command builder providing such interface that was updated recently or provide a large test coverage.\n\n## Features\n\n- Use a fluent API to construct the string to be executed\n- Class-based\n- Support arguments, long/short options and flags\n- Preserves order of elements\n- Does **not** handle executing the command\n\n## Installation\n\nInstall the package using Composer:\n\n```bash\ncomposer require khalyomede/command-builder\n```\n\n## Examples\n\n- [1. Create a simple command](#1-create-a-simple-command)\n- [2. Add an argument](#2-add-an-argument)\n- [3. Add a flag](#3-add-a-flag)\n- [4. Add an option](#4-add-an-option)\n- [5. Configure the standard](#5-configure-the-standard)\n- [6. Get the number of arguments](#6-get-the-number-of-arguments)\n- [7. Get the number of flags](#7-get-the-number-of-flags)\n- [8. Get the number of options](#8-get-the-number-of-options)\n- [9. Check if a flag has been added](#9-check-if-a-flag-has-been-added)\n- [10. Check if an option has been added](#10-check-if-an-option-has-been-added)\n\n### 1. Create a simple command\n\nIn this example, we will just pass a command name, without arguments/options/flags.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\necho $command; // composer\n```\n\n### 2. Add an argument\n\nIn this example, we will add an argument to our command.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003eargument(\"require\");\n\necho $command; // composer require\n```\n\n### 3. Add a flag\n\nIn this example, we will add a \"long\" flag to the command.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003eargument(\"require\")\n  -\u003elongFlag(\"ignore-platform-reqs\");\n\necho $command; // composer require --ignore-platform-reqs\n```\n\nAnd this is how to add a \"short\" flag.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003eargument(\"require\")\n  -\u003eflag(\"i\");\n\necho $command; // composer require -i\n```\n\n### 4. Add an option\n\nYou can add options to your command.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003eargument(\"require\")\n  -\u003elongOption(\"prefer-install\", \"source\");\n\necho $command; // composer require --prefer-install=source\n```\n\nIf your option contains spaces, it will automatically be escaped using double quotes.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003eargument(\"require\")\n  -\u003elongOption(\"prefer-install\", \"auto source\");\n\necho $command; // composer require --prefer-install=\"auto source\"\n```\n\nAnd if your option contains spaces and doubles quotes, they will also be escaped.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003eargument(\"require\")\n  -\u003elongOption(\"prefer-install\", 'auto \"source\"');\n\necho $command; // composer require --prefer-install=\"auto \\\"source\\\"\"\n```\n\nYou can also use \"short\" option.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003eargument(\"require\")\n  -\u003eoption(\"p\", 'source');\n\necho $command; // composer require -p=source\n```\n\n### 5. Configure the standard\n\nYou can specify the standard used for the option. By default, it is set to \"GNU\".\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\", \"POSIX\");\n\n$command-\u003eargument(\"require\")\n  -\u003eoption(\"p\", 'source');\n\necho $command; // composer require -p source\n\n$command = new Command(\"composer\")\n\n$command-\u003eargument(\"require\")\n  -\u003eoption(\"p\", 'source');\n\necho $command; // composer require -p=source\n```\n\nYou can also use constants if you prefer\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\nuse Khalyomede\\CommandBuilder\\Standard;\n\n$command = new Command(\"composer\", Standard::POSIX);\n```\n\n### 6. Get the number of arguments\n\nYou can know how many arguments were added to the command.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003eargument(\"create-project\")\n  -\u003eargument(\"laravel/laravel\");\n\necho $command-\u003eargumentCount(); // 2\n```\n\n### 7. Get the number of flags\n\nYou can know the number of flags added to your command.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003eflag(\"i\")\n  -\u003elongFlag(\"prefer-dist\");\n\necho $command-\u003eflagCount(); // 2\n```\n\n### 8. Get the number of options\n\nYou can know the number of options added to your command.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003eoption(\"a\", \"source\")\n  -\u003elongFlag(\"apcu-autoloader-prefix\", \"app\");\n\necho $command-\u003eoptionCount(); // 2\n```\n\n### 9. Check if a flag has been added\n\nYou can know if a flag has been added already.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\n\n$command = new Command(\"composer\");\n\n$command-\u003elongFlag(\"dev\");\n\nvar_dump( $command-\u003ehasFlag(\"d\", \"dev\") ); // bool(true)\nvar_dump( $command-\u003ehasFlag(\"o\", \"optimize-autoloader\") ); // bool(false)\n```\n\n### 10. Check if an option has been added\n\nYou can know if an option has been added or not.\n\n```php\nuse Khalyomede\\CommandBuilder\\Command;\nuse Khalyomede\\CommandBuilder\\Style;\n\n$command = new Command(\"composer\");\n\n$command-\u003elongOption(\"prefer-install\", \"source\");\n\nvar_dump( $command-\u003ehasOption(\"p\", \"prefer-install\") ); // bool(true)\nvar_dump( $command-\u003ehasOption(\"i\", \"ignore-platform-req\") ); // bool(false)\n```\n\n## Compatibility table\n\nThis is the compatibility for this version only. To check the compatibility with other version of this package, please browse the version of your choice.\n\n| PHP Version | Compatibility |\n|-------------|---------------|\n| 8.1.*       | ✔️             |\n| 8.0.*       | ✔️             |\n| 7.4.*       | ✔️             |\n\n## Tests\n\n```bash\ncomposer run test\ncomposer run mutate\ncomposer run analyse\ncomposer run lint\ncomposer run install-security-checker\ncomposer run check-security\ncomposer run check-updates\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalyomede%2Fcommand-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhalyomede%2Fcommand-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalyomede%2Fcommand-builder/lists"}