{"id":18640340,"url":"https://github.com/enxebre/cligenerator","last_synced_at":"2025-11-04T20:30:23.972Z","repository":{"id":17251494,"uuid":"20020888","full_name":"enxebre/CliGenerator","owner":"enxebre","description":"A Command-Line User Interface generator for Symfony Console Component.","archived":false,"fork":false,"pushed_at":"2014-09-12T11:26:32.000Z","size":204,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-27T10:08:52.044Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"shrekshrek/css3d-engine","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/enxebre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-21T12:47:33.000Z","updated_at":"2016-06-25T03:05:03.000Z","dependencies_parsed_at":"2022-09-09T15:51:24.539Z","dependency_job_id":null,"html_url":"https://github.com/enxebre/CliGenerator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enxebre%2FCliGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enxebre%2FCliGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enxebre%2FCliGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enxebre%2FCliGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enxebre","download_url":"https://codeload.github.com/enxebre/CliGenerator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239441663,"owners_count":19639122,"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":[],"created_at":"2024-11-07T05:54:01.128Z","updated_at":"2025-11-04T20:30:23.900Z","avatar_url":"https://github.com/enxebre.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"CliGenerator is a tool for creating cli from configuration files (.json, .yaml, etc.) extending [Console Symfony Component](https://github.com/symfony/Console)\n============================================================================================\n[![Build Status](https://travis-ci.org/enxebre/CliGenerator.png?branch=master)](https://travis-ci.org/enxebre/CliGenerator)\n \nCliGenerator (command-line interface generator) is a library that complements the Symfony Console Component\nproviding a tool for generating loads of commands dynamically from a given\nsource (.json file, method returning an array, .yaml file, etc.).\n\nThis library is on [packagist](https://packagist.org/packages/enxebre/cli-generator)\n\n### Installing via Composer\n\nThe recommended way to install CliGenerator is through [Composer](http://getcomposer.org).\n\n```bash\n# Install Composer\ncurl -sS https://getcomposer.org/installer | php\n```\n\nAdding CliGenerator:\nAdd to your current composer.json ```require``` key: ```\"enxebre/cli-generator\":\"1.0.*\" ```\n\nAfter installing, you need to require Composer's autoloader:\n\n```php\nrequire 'vendor/autoload.php';\n```\n\n##Usage##\n\n```php\n$cliManager = new cliManager(new cliDiscovery(new cliYourResourceBuilder($your_source_file)), $YourcliClassName);\n\n$application = new Application();\n$application-\u003eaddCommands($cliManager-\u003egenerateCli());\n$application-\u003erun();\n```\n\nAll you need to do is to create a \"CliManager\" Class and pass the generated commands\nto your console application like in the example above.\n\nYou should implement the \"CliResourceBuilderInterface\" interface for returning\nthe definitions that will be used for your \"CustomCli\" Class for\nbuilding the load of commands.\n\n##Example##\n\nSome use cases would be a REST API Cli ( you could use [Guzzle](https://github.com/guzzle/guzzle)) or a Database Cli among others.\n\nDynamic Calculator Cli:\nThe next one is an example tested in the library suite tests. See CliCalculatorTest.php\n\nDefinition:\n\n```json\n{\n    \"absolute\":\n    {\n        \"name\":\"calculator:abs\",\n        \"description\":\"Absolute value.\",\n        \"operator\":\"abs\",\n        \"parameters\":\n        {\n            \"value1\":{\n                \"description\":\"first value\"\n            }\n        }\n    },\n    \"maximum\":\n    {\n        \"name\":\"calculator:max\",\n        \"description\":\"Maximum of params.\",\n        \"operator\":\"max\",\n        \"parameters\":\n        {\n            \"value1\":\n            {\n                \"description\":\"first value\"\n            },\n            \"value2\":\n            {\n                \"description\":\"second value\"\n            }\n        }\n    },\n    \"minimum\":\n    {\n        \"name\":\"calculator:min\",\n        \"description\":\"Minimum of params.\",\n        \"operator\":\"min\",\n        \"parameters\":\n        {\n            \"value1\":\n            {\n                \"description\":\"first value\"\n            },\n            \"value2\":\n            {\n                \"description\":\"second value\"\n            }\n        }\n    },\n    \"Cosine\":\n    {\n        \"name\":\"calculator:cos\",\n        \"description\":\"Cosine calculator.\",\n        \"operator\":\"cos\",\n        \"parameters\":\n        {\n            \"value1\":\n            {\n                \"description\":\"first value\"\n            }\n        }\n    },\n    \"Sin\":\n    {\n        \"name\":\"calculator:sin\",\n        \"description\":\"Sine of params.\",\n        \"operator\":\"sin\",\n        \"parameters\":\n        {\n            \"value1\":\n            {\n                \"description\":\"first value\"\n            }\n        }\n    },\n    \"Tan\":\n    {\n        \"name\":\"calculator:tan\",\n        \"description\":\"Tangent calculator.\",\n        \"operator\":\"tan\",\n        \"parameters\":\n        {\n            \"value1\":\n            {\n                \"description\":\"first value\"\n            }\n        }\n    }\n}\n```\n\nResource builder:\n\n```php\nClass CalculatorResourceBuilder implements CliResourceBuilderInterface\n{\n\n    private $source;\n\n    /**\n     * @param mixed $source\n     */\n    public function setSource($source)\n    {\n        $this-\u003esource = $source;\n    }\n\n    /**\n     * @return mixed\n     */\n    public function getSource()\n    {\n        return $this-\u003esource;\n    }\n    /**\n     * Constructor.\n     *\n     * @param null $source The source where live our cli definitions.\n     */\n    public function __construct($source = '/CalculatorDefinition.json') {\n        $this-\u003esetSource(dirname(__FILE__) . $source);\n    }\n\n    /**\n     * Responsible for parser a given source and turning\n     * it into an array usable by a custom comand class.\n     *\n     * @return array of the definitions\n     *\n     * @api\n     */\n    public function buildDefinitions() {\n\n        $jsonDefinition = file_get_contents($this-\u003egetSource());\n        $arrayDefinition = json_decode($jsonDefinition, TRUE);\n        return $arrayDefinition;\n    }\n}\n```\n\nCustom Cli class:\n\n```php\nclass CalculatorCli extends \\CliGenerator\\CliBase\n{\n\n    private $operator = '';\n\n    /**\n     * @param string $operator\n     */\n    public function setOperator($operator)\n    {\n        $this-\u003eoperator = $operator;\n    }\n\n    /**\n     * @return string\n     */\n    public function getOperator()\n    {\n        return $this-\u003eoperator;\n    }\n\n    protected function configure()\n    {\n\n        $definition = $this-\u003egetCommandDefinition();\n        $this\n            -\u003esetDescription($definition['description'])\n        ;\n\n        $this-\u003esetOperator($definition['operator']);\n\n        foreach($definition['parameters'] as $param =\u003e $details) {\n            $this-\u003eaddArgument(\n                $param,\n                null,\n                \"Introduce a ${details['description']}.\"\n            );\n        }\n    }\n\n    protected function execute(InputInterface $input, OutputInterface $output)\n    {\n\n        $operator = $this-\u003egetOperator();\n\n        if ($input-\u003ehasArgument('value2')) {\n            $result = $operator($input-\u003egetArgument('value1'), $input-\u003egetArgument('value2'));\n        }\n        else {\n            $result = $operator($input-\u003egetArgument('value1'));\n        }\n\n        $output-\u003ewrite($result);\n\n    }\n}\n```\n\nYou could now add as many commands as you want to your CLI just modifying the definition.json file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenxebre%2Fcligenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenxebre%2Fcligenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenxebre%2Fcligenerator/lists"}