ruby_cli 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.rdoc +36 -4
  2. data/lib/ruby_cli.rb +0 -1
  3. 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
- if __FILE__ == $0
95
- app = App.new(ARGV)
96
- app.run
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
@@ -6,7 +6,6 @@ require 'optparse'
6
6
  #
7
7
  # See README.rdoc for more information.
8
8
  module RubyCLI
9
-
10
9
 
11
10
  # Initialization of this application requires the command line arguments.
12
11
  def initialize(default_argv, command_name, usage = "[OPTIONS]... [ARGUMENTS]...")
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Martin Velez