ruby_cli 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +36 -4
- data/lib/ruby_cli.rb +0 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -83,7 +83,7 @@ This example demonstrates how to use RubyCLI to create a command line applicatio
|
|
83
83
|
require 'ruby_cli'
|
84
84
|
|
85
85
|
class App
|
86
|
-
include RubyCLI
|
86
|
+
include RubyCLI
|
87
87
|
|
88
88
|
def command
|
89
89
|
puts "hello world"
|
@@ -91,11 +91,43 @@ This example demonstrates how to use RubyCLI to create a command line applicatio
|
|
91
91
|
|
92
92
|
end
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
app = App.new(ARGV)
|
95
|
+
app.run
|
96
|
+
|
97
|
+
== Usage Example 2
|
98
|
+
|
99
|
+
This example demonstrates how command specific options can be defined easily using
|
100
|
+
RubyCLI. It is taken from the ruby_ngrams[https://github.com/martinvelez/ruby_ngrams]
|
101
|
+
gem executable, which I also authored.
|
102
|
+
|
103
|
+
#!/usr/bin/env ruby
|
104
|
+
|
105
|
+
require 'ruby_cli'
|
106
|
+
require 'ruby_ngrams'
|
107
|
+
|
108
|
+
class App
|
109
|
+
include RubyCLI
|
110
|
+
|
111
|
+
def initialize_command_options() @options = {:regex => //, :n => 2} end
|
112
|
+
|
113
|
+
def define_command_option_parsing
|
114
|
+
@opt_parser.on('-n', '--n NUM', Integer, 'set length n for n-grams') do |n|
|
115
|
+
@options[:n] = n
|
116
|
+
end
|
117
|
+
@opt_parser.on('-r', '--regex "REGEX"', Regexp, 'set regex to split string into tokens') do |r|
|
118
|
+
@options[:regex] = r
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def command
|
123
|
+
text = ARGF.read
|
124
|
+
text.ngrams(@options).each { |ngram| puts ngram.inspect }
|
125
|
+
end
|
97
126
|
end
|
98
127
|
|
128
|
+
app = App.new(ARGV, __FILE__)
|
129
|
+
app.run
|
130
|
+
|
99
131
|
= Dependencies
|
100
132
|
|
101
133
|
* Ruby 1.8.7 or greater
|
data/lib/ruby_cli.rb
CHANGED