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 +2 -2
- data/lib/linen/argument.rb +12 -18
- data/lib/linen/cli.rb +5 -7
- data/lib/linen/command.rb +3 -9
- data/test/test_plugins.rb +0 -1
- metadata +1 -1
data/lib/linen.rb
CHANGED
data/lib/linen/argument.rb
CHANGED
@@ -11,28 +11,22 @@ class Linen::Plugin::Argument
|
|
11
11
|
attr_reader :prompt
|
12
12
|
|
13
13
|
def initialize( plugin, name, opts )
|
14
|
-
@plugin
|
15
|
-
@name
|
16
|
-
@prompt
|
17
|
-
@
|
18
|
-
@
|
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
|
23
|
-
|
24
|
-
return
|
25
|
-
end
|
26
|
-
|
22
|
+
def process( value )
|
23
|
+
raise Linen::Plugin::ArgumentError unless value =~ @regex
|
24
|
+
return value unless @process
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
127
|
-
|
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.
|
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.
|
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