Categories: None [Edit]
rake-toolkit_program
# Rake::ToolkitProgram
Create toolkit programs easily with `Rake` and `OptionParser` syntax. Bash completions and usage help are baked in.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'rake-toolkit_program'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install rake-toolkit_program
## Quickstart
* Shebang it up (in a file named `awesome_tool.rb`)
```ruby
#!/usr/bin/env ruby
```
* Require the library
```ruby
require 'rake/toolkit_program'
```
* Make your life easier
```ruby
Program = Rake::ToolkitProgram
```
* Define your command tasks
```ruby
Program.command_tasks do
desc "Build it"
task 'build' do
# Ruby code here
end
desc "Test it"
task 'test' => ['build'] do
# Rake syntax ↑↑↑↑↑↑↑ for dependencies
# Ruby code here
end
end
```
You can use `Program.args` in your tasks to access the other arguments on the command line. For argument parsing integrated into the help provided by the program, see the use of `Rake::Task(Rake::ToolkitProgram::TaskExt)#parse_args` below.
* Wire the mainline
```ruby
Program.run(on_error: :exit_program!) if $0 == __FILE__
```
* In the shell, prepare to run the program (UNIX/Linux systems only)
```console
$ chmod +x awesome_tool.rb
$ ./awesome_tool.rb --install-completions
Completions installed in /home/rtweeks/.bashrc
Source /home/rtweeks/.bash-complete/awesome_tool.rb-completions for immediate availability.
$ source /home/rtweeks/.bash-complete/awesome_tool.rb-completions
```
* Ask for help
```console
$ ./awesome_tool.rb help
*** ./awesome_tool.rb Toolkit Program ***
.
.
.
```
## Usage
Let's look at a short sample toolkit program -- put this in `awesome.rb`:
```ruby
#!/usr/bin/env ruby
require 'rake/toolkit_program'
require 'ostruct'
ToolkitProgram = Rake::ToolkitProgram
ToolkitProgram.title = "My Awesome Toolkit of Awesome"
ToolkitProgram.command_tasks do
desc <<-END_DESC.dedent
Fooing my...
Total
Ranking: 139,166 of 183,477
Downloads: 3,873
Daily
Ranking: 30,305 of 183,470
Downloads: 2
Downloads Trends
Ranking Trends
Num of Versions Trends
Popular Versions (Major)
Popular Versions (Major.Minor)
Depended by
Rank | Downloads | Name |
---|---|---|
56,012 | 17,369 | myprecious |
Owners
# | Gravatar | Handle |
---|---|---|
1 | rtweeks |