{"id":21056019,"url":"https://github.com/xp-framework/command","last_synced_at":"2026-01-05T10:49:18.608Z","repository":{"id":3391620,"uuid":"49331416","full_name":"xp-framework/command","owner":"xp-framework","description":"Commands, a.k.a. xpcli","archived":false,"fork":false,"pushed_at":"2024-03-28T20:21:59.000Z","size":140,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T02:41:29.071Z","etag":null,"topics":["argument-parser","command-line","php","xp-framework"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xp-framework.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":null,"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":"2016-01-09T16:19:49.000Z","updated_at":"2021-10-21T17:48:31.000Z","dependencies_parsed_at":"2024-03-24T11:27:28.809Z","dependency_job_id":"73b54837-c4d8-46e4-8612-f10e96971307","html_url":"https://github.com/xp-framework/command","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fcommand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fcommand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fcommand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fcommand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-framework","download_url":"https://codeload.github.com/xp-framework/command/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245372217,"owners_count":20604488,"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":["argument-parser","command-line","php","xp-framework"],"created_at":"2024-11-19T16:48:20.158Z","updated_at":"2026-01-05T10:49:18.471Z","avatar_url":"https://github.com/xp-framework.png","language":"PHP","readme":"Commands\n========\n\n[![Build status on GitHub](https://github.com/xp-framework/command/workflows/Tests/badge.svg)](https://github.com/xp-framework/command/actions)\n[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)\n[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)\n[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)\n[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)\n[![Latest Stable Version](https://poser.pugx.org/xp-framework/command/version.svg)](https://packagist.org/packages/xp-framework/command)\n\nAlso known as \"xpcli\": Command line argument parsing via annotations.\n\nExample\n-------\n\n```php\nuse util\\cmd\\{Command, Arg};\nuse rdbms\\DriverManager;\nuse io\\streams\\Streams;\n\n/** Performs an SQL query */\nclass Query extends Command {\n  private $connection, $query;\n  private $verbose= false;\n\n  /** Connection DSN, e.g. `mysql://user:pass@host[:port][/database]` */\n  #[Arg(position: 0)]\n  public function useConnection(string $dsn) {\n    $this-\u003econnection= DriverManager::getConnection($dsn);\n    $this-\u003econnection-\u003econnect();\n  }\n\n  /** SQL query. Use `-` to read from standard input */\n  #[Arg(position: 1)]\n  public function useQuery(string $query) {\n    if ('-' === $query) {\n      $this-\u003equery= Streams::readAll($this-\u003ein-\u003estream());\n    } else {\n      $this-\u003equery= $query;\n    }\n  }\n\n  /** Verbose output */\n  #[Arg]\n  public function useVerbose() {\n    $this-\u003everbose= true;\n  }\n\n  /** @return int */\n  public function run() {\n    $this-\u003everbose \u0026\u0026 $this-\u003eout-\u003ewriteLine('@ ', $this-\u003econnection);\n    $this-\u003everbose \u0026\u0026 $this-\u003eout-\u003ewriteLine('\u003e\u003e\u003e ', $this-\u003equery);\n\n    $result= $this-\u003econnection-\u003eopen($this-\u003equery);\n    if ($result-\u003eisSuccess()) {\n      $this-\u003everbose \u0026\u0026 $this-\u003eout-\u003ewriteLine('\u003c\u003c\u003c ', $result-\u003eaffected());\n      return $result-\u003eaffected() ? 0 : 1;\n    } else {\n      $this-\u003everbose \u0026\u0026 $this-\u003eout-\u003ewriteLine('\u003c\u003c\u003c Results');\n      foreach ($result as $found =\u003e $record) {\n        $this-\u003eout-\u003ewriteLine($record);\n      }\n      return isset($found) ? 0 : 2;\n    }\n  }\n}\n```\n\nTo execute the class, use the `cmd` command:\n\n```sh\n$ xp -m /path/to/rdbms cmd Query 'mysql://localhost/test' 'select * from account' -v\n@ rdbms.mysqlx.MySqlxConnection(-\u003erdbms.DSN@(mysql://localhost/test), rdbms.mysqlx.MySqlxProtocol(...)\n\u003e\u003e\u003e select * from account\n\u003c\u003c\u003c Results\n[\n  account_id =\u003e 1\n  username =\u003e \"kiesel\"\n  email =\u003e \"alex.dandrea@example.com\"\n]\n[\n  account_id =\u003e 2\n  username =\u003e \"thekid\"\n  email =\u003e \"timm.friebe@example.com\"\n]\n```\n\nTo show the command's usage, supply `-?` or `--help`:\n\n![query-class-usage](https://github.com/xp-framework/command/assets/696742/7ca5d4c8-d17c-4f18-8c3a-7903c7449357)\n\nSee also\n--------\n\n* [RFC #0133](https://github.com/xp-framework/rfc/issues/133) - Add support for filenames as argument for XPCLI\n* [RFC #0102](https://github.com/xp-framework/rfc/issues/102) - XP Class Runners *(original RFC)*","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Fcommand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-framework%2Fcommand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Fcommand/lists"}