{"id":21540502,"url":"https://github.com/othercodes/cli","last_synced_at":"2025-09-07T00:41:46.056Z","repository":{"id":52415552,"uuid":"71809428","full_name":"othercodes/cli","owner":"othercodes","description":"Basic structure to develop CLI commands.","archived":false,"fork":false,"pushed_at":"2021-04-29T20:43:33.000Z","size":21,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-17T21:56:38.024Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/othercodes.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":"2016-10-24T16:37:00.000Z","updated_at":"2020-10-14T07:17:02.000Z","dependencies_parsed_at":"2022-08-23T20:50:38.515Z","dependency_job_id":null,"html_url":"https://github.com/othercodes/cli","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/othercodes/cli","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othercodes%2Fcli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othercodes%2Fcli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othercodes%2Fcli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othercodes%2Fcli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/othercodes","download_url":"https://codeload.github.com/othercodes/cli/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othercodes%2Fcli/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273983073,"owners_count":25202092,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-24T04:19:11.472Z","updated_at":"2025-09-07T00:41:46.001Z","avatar_url":"https://github.com/othercodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Command Line Framework\n\nSmall command line framework to build multi-level chained commands. Offer a small writter and formatter system to print \nmessages with custom format (colors and style like bold or underline).\n\n## Requirements\n\n* PHP \u003e= 5.4.*\n* PHP Readline extension\n\n## Usage\n\nFirst we need to create an application: `\\App\\CLIApplication.php`\n\n```\n\u003c?php \n\nclass CLIApplication extends \\OtherCode\\CLI\\Command\n{\n\n    /**\n     * Command name\n     */\n    const NAME = 'SampleCLIApplication';\n\n    /**\n     * Current version\n     */\n    const VERSION = \"1.0.0\";\n\n    /**\n     * Available commands\n     * @var array\n     */\n    protected $commands = array(\n        'hello' =\u003e 'Sample\\App\\Commands\\HelloCommand',\n    );\n\n    /**\n     * Display a description message\n     * @return string\n     */\n    public function description()\n    {\n        return \"Sample CLI Application.\";\n    }\n\n}\n```\n\nNex we create the entry point: `\\app.php`\n\n```\n\u003c?php\n\n/**\n * Include the core library\n */\nrequire_once '../autoload.php';\n\n/**\n * Include the app files (commands and libs)\n */\nrequire_once 'App/CLIApplication.php';\nrequire_once 'App/Commands/HelloCommand.php';\n\n/**\n * Command line entry point\n */\n$app = new Sample\\App\\CLIApplication();\n$app-\u003ebootstrap($argv);\n$app-\u003eexecute();\n```\n\nFinally we can add all the sub-commands we want, for example:\n\n```\n\u003c?php\n\nnamespace Sample\\App\\Commands;\n\n/**\n * Class HelloCommand\n * @package Sample\\App\n */\nclass HelloCommand extends \\OtherCode\\CLI\\Command\n{\n    /**\n     * Display a description message\n     * @return string\n     */\n    public function description()\n    {\n        return \"Say hello world!\";\n    }\n\n    /**\n     * Main code\n     * @param null $payload\n     * @return mixed|void\n     */\n    public function run($payload = null)\n    {\n        $this-\u003ewritter-\u003einfo('Hello World Info');\n\n        $this-\u003ewritter-\u003einput(\"do yo like it?\", 'n', true);\n    }\n}\n```\n\nOur main code is located in the `run()` method, we also can put some code into `initialize()` and `finish()` methods. the\n`initialize()` method is executed before the `run()` method, and the `finish()` method is executed after the run method.\n\nThe output of the `run()` is passed to the child command so we can use it as argument. Finally the output of the child command is\npassed again to the parent command in the `finish()` method.\n\nThe only required method top execute a command is `run()`.\n\nIts time to run the command:\n\n```\n$ php app.php\n\nSample CLI Application.\nSampleCLIApplication v1.0.0\n\n Options:\n   -h|help  Show help information.\n\n Commands:\n   hello  Say hello world!\n```\n\nRunning the sub-command.\n```   \n$ php app.php hello\n\nHello World Info\ndo yo like it? [n]: yes\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fothercodes%2Fcli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fothercodes%2Fcli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fothercodes%2Fcli/lists"}