linen 0.3.2 → 0.4.0

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.
data/lib/linen.rb CHANGED
@@ -18,8 +18,8 @@ require 'string_extensions'
18
18
 
19
19
 
20
20
  module Linen
21
- VERSION = "0.3.2"
22
- SVNRev = %q$Rev: 86 $
21
+ VERSION = "0.4.0"
22
+ SVNRev = %q$Rev: 99 $
23
23
 
24
24
 
25
25
  def self::plugins
@@ -11,28 +11,22 @@ class Linen::Plugin::Argument
11
11
  attr_reader :prompt
12
12
 
13
13
  def initialize( plugin, name, opts )
14
- @plugin = plugin
15
- @name = name
16
- @prompt = opts[:prompt] || "Please enter the value for #{@name}"
17
- @validation = opts[:validation] || /^\w+$/
18
- @conversion = opts[:conversion] || nil
14
+ @plugin = plugin
15
+ @name = name
16
+ @prompt = opts[ :prompt ] || "Please enter the value for #{@name}"
17
+ @regex = opts[ :regex ] || /^\w+$/
18
+ @process = opts[ :process ] || nil
19
19
  end
20
20
 
21
21
 
22
- def convert( value )
23
- return value unless @conversion
24
- return @conversion.call( value )
25
- end
26
-
22
+ def process( value )
23
+ raise Linen::Plugin::ArgumentError unless value =~ @regex
24
+ return value unless @process
27
25
 
28
- def validate( value )
29
- if @validation.is_a? Proc
30
- result = @validation.call( value )
31
- else
32
- result = ( value =~ @validation )
26
+ begin
27
+ return @process.call( value )
28
+ rescue => e
29
+ raise Linen::Plugin::ArgumentError, e.message
33
30
  end
34
-
35
- raise Linen::Plugin::ArgumentError, "Value '#{value}' is invalid for #{@name}." unless result
36
- return value
37
31
  end
38
32
  end
data/lib/linen/cli.rb CHANGED
@@ -121,14 +121,12 @@ class Linen::CLI
121
121
  input = Readline.readline( "\nContinue [y/N]? ")
122
122
  input = "n" if input == ''
123
123
  end
124
+
125
+ return unless input =~ /^y/i
124
126
  end
125
-
126
- if input =~ /^y/i
127
- puts # blank line
128
-
129
- workspace.add_values( results )
130
- command.execute( workspace )
131
- end
127
+
128
+ workspace.add_values( results )
129
+ command.execute( workspace )
132
130
  end
133
131
 
134
132
 
data/lib/linen/command.rb CHANGED
@@ -33,7 +33,7 @@ class Linen::Plugin::Command
33
33
 
34
34
  # this map turns our list of args into a list like this:
35
35
  # <arg1> <arg2> <arg3> <arg4>...
36
- arg_list = arguments.map {|a| "<#{a.to_s}>"}.join( ' ' )
36
+ arg_list = @arguments.map {|a| "<#{a.to_s}>"}.join( ' ' )
37
37
 
38
38
  output << "Usage: #{@plugin.short_name} #{name} #{arg_list}"
39
39
 
@@ -130,13 +130,12 @@ class Linen::Plugin::Command
130
130
  @arguments.each do |arg_name|
131
131
  argument = @plugin.arguments[ arg_name ]
132
132
 
133
- results[ arg_name ] = argument.validate( arg ) rescue nil
133
+ results[ arg_name ] = argument.process( arg ) rescue nil
134
134
  end
135
135
 
136
136
  raise Linen::Plugin::ArgumentError,
137
137
  "The value you entered ('#{arg}') is invalid for all arguments." if
138
138
  results.values.compact.empty?
139
-
140
139
  rescue Linen::Plugin::ArgumentError => e
141
140
  print "#{e} "
142
141
 
@@ -159,17 +158,12 @@ class Linen::Plugin::Command
159
158
  begin
160
159
  arg_value = Linen::CLI.reprompt( argument.prompt ) if arg_value.nil?
161
160
 
162
- argument.validate arg_value
163
-
161
+ results[ arg_name ] = argument.process( arg_value )
164
162
  rescue Linen::Plugin::ArgumentError => e
165
- print "#{e} "
166
-
167
163
  # reset arg_value to nil so we get prompted on retry
168
164
  arg_value = nil
169
165
 
170
166
  retry
171
- else
172
- results[ arg_name ] = argument.convert( arg_value )
173
167
  end
174
168
  end
175
169
 
data/test/test_plugins.rb CHANGED
@@ -35,7 +35,6 @@ class TestPlugins < Test::Unit::TestCase
35
35
  ################
36
36
 
37
37
  class ::HelpfulPlugin < Linen::Plugin
38
- puts TestPlugins.description
39
38
  description TestPlugins.description
40
39
 
41
40
  command :test do
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: linen
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.2
6
+ version: 0.4.0
7
7
  date: 2007-09-10 00:00:00 -07:00
8
8
  summary: Linen - A pluggable command-line interface library
9
9
  require_paths: