{"id":26236795,"url":"https://github.com/yuri-karpovich/console_runner","last_synced_at":"2025-04-22T19:20:55.120Z","repository":{"id":62556179,"uuid":"82353495","full_name":"yuri-karpovich/console_runner","owner":"yuri-karpovich","description":"Run any *.rb file from command line. CLI for Ruby classes. It's like Python Fire but for Ruby!","archived":false,"fork":false,"pushed_at":"2021-07-21T14:26:48.000Z","size":84,"stargazers_count":6,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T13:21:29.335Z","etag":null,"topics":["annotations","bash","cli","command-line","command-line-tool","console","devops","executable","parser","ruby","ruby-gem","trollop","yard","yardoc"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/yuri-karpovich.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-18T01:50:21.000Z","updated_at":"2021-07-21T14:26:51.000Z","dependencies_parsed_at":"2022-11-03T06:00:26.709Z","dependency_job_id":null,"html_url":"https://github.com/yuri-karpovich/console_runner","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuri-karpovich%2Fconsole_runner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuri-karpovich%2Fconsole_runner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuri-karpovich%2Fconsole_runner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuri-karpovich%2Fconsole_runner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuri-karpovich","download_url":"https://codeload.github.com/yuri-karpovich/console_runner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250306601,"owners_count":21408927,"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":["annotations","bash","cli","command-line","command-line-tool","console","devops","executable","parser","ruby","ruby-gem","trollop","yard","yardoc"],"created_at":"2025-03-13T04:18:39.652Z","updated_at":"2025-04-22T19:20:54.986Z","avatar_url":"https://github.com/yuri-karpovich.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ConsoleRunner [CLI for any *.rb]\n[![Gem Version][GV img]][Gem Version]\n[![Build Status][BS img]][Build Status]\n[![Code Climate][CC img]][Code Climate]\n[![Coverage Status][CS img]][Coverage Status]\n\nThis gem provides you an ability to run any Ruby method from command-line. No special code modifications required!.\n`console_runner` is a smart mix of [YARD](http://yardoc.org/) and [Optimist](http://manageiq.github.io/optimist/) gems. \nIt's an analog of [Python Fire](https://github.com/google/python-fire) but for Ruby.  \n\u003e 1. it parses [YARD](http://yardoc.org/) annotations of classes and methods to 'understand' your code\n\u003e 2. it generates friendly unix-like help menu for your tool (using [Optimist](http://manageiq.github.io/optimist/) gem)\n\u003e 3. it parses command-line input and run your Ruby code in a proper way \n\nOne thing you need to do is to add `@runnable` tag to your method annotation.\n\n## Usage\n`console_runner` extends [YARD](http://yardoc.org/) with a new tag: `@runnable`. You need to set this tag in a Class and Method annotation. After that it will be possible to call this method from command-line.\nUsage instructions are as simple as one, two, three:\n1. Add `@runnable` tag\n2. Now you can run your tool from terminal by `c_run /path/to/class.rb_file` command\n3. PROFIT! \n\n### Example\n1. Install `console_runner` gem\n2. Put some code to `/home/user/project/my_class.rb`\n```ruby\n# @runnable\nclass MyClass\n\n    # @runnable\n    def say_hello\n      puts 'Hello!'\n    end\n    \nend\n```\n3. Run terminal command to run `say_hello` method\n```bash\nc_run /home/user/project/my_class.rb say_hello\n\n-\u003e Hello!\n```\n\nRead FAQ for more examples.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'console_runner'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install console_runner\n\n## FAQ\n#### **Can I add documentation for my tool and customize help page content?**\nYes. Any text placed after `@runnable` tag will be displayed on the help page. You can add any additional information about how to use your tool there.\n\u003e **Tip**: You can use multi-line text as well\n\n##### Example:\n```ruby\n# @runnable This tool can talk to you. Run it when you are lonely.\n#   Written in Ruby.  \nclass MyClass\n\n    def initialize\n      @hello_msg = 'Hello!' \n      @bye_msg = 'Good Bye!' \n    end\n    \n    # @runnable Say 'Hello' to you.\n    # @param [String] name Your name\n    def say_hello(name)\n      puts @hello_msg + ', ' + name\n    end\n    \n    # @runnable Say 'Good Bye' to you.\n    def say_bye\n      puts @bye_msg\n    end\n    \nend\n```\n\n```bash\n ~\u003e c_run /projects/example/my_class.rb  --help\nOptions:\n  --debug    Run in debug mode.\n\nThis tool can talk to you. Run it when you are lonely.\nWritten in Ruby.\n\nAvailable actions:\n        - say_hello\n                Say 'Hello' to you.\n        - say_bye\n                Say 'Good Bye' to you.\n```\n\n```bash\n ~\u003e c_run /projects/example/my_class.rb  say_hello -h\nOptions:\n  -d, --debug    Run in debug mode.\n  -h, --help     Show this message\n  --name=\u003cs\u003e     (Ruby class: String) Your name\n\nSay 'Hello' to you.\n\n```\n#### **Can I send parameters to my methods?**\nYes, `console_runner` parses YARD annotation (`@param` and `@option` tags) and check the list of parameters for your method.\n\n\u003e *Restriction*: You can use Hash parameters as well (for storing options). But you cannot use the same name for parameter and for option. \n\u003e \n\u003e For example, `def limit(number, options = {number: 5})...` - `number` name is not allowed. You should use another parameter name.\n\n##### Example:\n```ruby\n# @runnable This tool can talk to you. Run it when you are lonely.\n#   Written in Ruby.  \nclass MyClass\n\n    def initialize\n      @hello_msg = 'Hello' \n      @bye_msg = 'Good Bye' \n    end\n    \n    # @runnable Say 'Hello' to you.\n    # @param [String] name Your name\n    # @param [Hash] options options\n    # @option options [Boolean] :second_meet Have you met before?\n    # @option options [String] :prefix Your custom prefix\n    def say_hello(name, options = {})\n      second_meet = nil\n      second_meet = 'Nice to see you again!' if options['second_meet']\n      prefix = options['prefix']\n      message = @hello_msg + ', '\n      message += \"#{prefix} \" if prefix\n      message += \"#{name}. \"\n      message += second_meet if second_meet\n      puts message\n    end\n    \nend\n```\n```bash\n~\u003e c_run /projects/example/my_class.rb  say_hello -h \nOptions:\n  -d, --debug      Run in debug mode.\n  -h, --help       Show this message\n  --name=\u003cs\u003e       (Ruby class: String) Your name\n  --second-meet    (Ruby class: Boolean) Have you met before?\n  --prefix=\u003cs\u003e     (Ruby class: String) Your custom prefix\n\nSay 'Hello' to you.\n```\n```bash\n~\u003e c_run /projects/example/my_class.rb  say_hello -n John --second-meet --prefix Mr. \nHello, Mr. John. Nice to see you again!\n```\n\n#### **Can I use optional parameters?**\nYes. All parameters with `@option` YARD tag are optional. \n\n`--second-meet` and `--prefix` parameters are optional in the following example:\n```ruby\n# @runnable Say 'Hello' to you.\n    # @param [String] name Your name\n    # @param [Hash] options options\n    # @option options [Boolean] :second_meet Have you met before?\n    # @option options [String] :prefix Your custom prefix\n```\nAnother approach is to use *default values* for parameters. \nParameter `--name` in the following example is optional because it has the default value `Chuck`.\n```ruby\n    # @runnable Say 'Hello' to you.\n    # @param [String] name Your name\n    # @param [Hash] options options\n    # @option options [Boolean] :second_meet Have you met before?\n    # @option options [String] :prefix Your custom prefix\n    def say_hello(name = 'Chuck', options = {})\n      second_meet = nil\n      second_meet = 'Nice to see you again!' if options['second_meet']\n      prefix = options['prefix']\n      message = @hello_msg + ', '\n      message += \"#{prefix} \" if prefix\n      message += \"#{name}. \"\n      message += second_meet if second_meet\n      puts message\n    end\n```\n```bash\n-\u003e c_run /projects/example/my_class.rb  say_hello  \nHello, Chuck. \n```\n#### **Is it works only for class methods?**\n`console_runner` works with both methods - **class** and **instance** methods. It's clear how it works with **class** method - method is called without any preconditions.\n**Instance** method will be called in accordance with following logic:\n 1. call `:initialize` method \n 2. call specified action method\n\n#### **My `require` code doesn't work well. How can I fix it?**\nUse `require_relative ` method instead.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/yuri-karpovich/console_runner.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n[Gem Version]: https://rubygems.org/gems/console_runner\n[Build Status]: https://travis-ci.org/yuri-karpovich/console_runner\n[travis pull requests]: https://travis-ci.org/yuri-karpovich/console_runner/pull_requests\n[Dependency Status]: https://gemnasium.com/github.com/yuri-karpovich/console_runner\n[Code Climate]: https://codeclimate.com/github/yuri-karpovich/console_runner\n[Coverage Status]: https://coveralls.io/github/yuri-karpovich/console_runner\n\n[GV img]: https://badge.fury.io/rb/console_runner.svg\n[BS img]: https://travis-ci.org/yuri-karpovich/console_runner.svg?branch=master\n[DS img]: https://gemnasium.com/badges/github.com/yuri-karpovich/console_runner.svg\n[CC img]: https://codeclimate.com/github/yuri-karpovich/console_runner.png\n[CS img]: https://coveralls.io/repos/github/yuri-karpovich/console_runner/badge.svg?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuri-karpovich%2Fconsole_runner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuri-karpovich%2Fconsole_runner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuri-karpovich%2Fconsole_runner/lists"}