linen 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/linen.rb CHANGED
@@ -18,8 +18,8 @@ require 'string_extensions'
18
18
 
19
19
 
20
20
  module Linen
21
- VERSION = "0.4.0"
22
- SVNRev = %q$Rev: 99 $
21
+ VERSION = "0.5.0"
22
+ SVNRev = %q$Rev: 119 $
23
23
 
24
24
 
25
25
  def self::plugins
@@ -27,9 +27,10 @@ module Linen
27
27
  end
28
28
 
29
29
 
30
- def self::start
31
- Linen::CLI.start_loop
32
- end
30
+ def self::start( handler = Linen::CLI )
31
+ Linen::Workspace.register_handler handler
32
+ handler.start
33
+ end
33
34
  end
34
35
 
35
36
 
@@ -40,7 +41,11 @@ require 'linen/argument'
40
41
  require 'linen/command'
41
42
 
42
43
 
44
+ ### handlers
45
+ require 'linen/handler'
46
+ require 'linen/handlers/cli'
47
+
48
+
43
49
  ### Other Infrastructure
44
- require 'linen/cli'
45
50
  require 'linen/exceptions'
46
51
  require 'linen/workspace'
@@ -14,7 +14,7 @@ class Linen::Plugin::Argument
14
14
  @plugin = plugin
15
15
  @name = name
16
16
  @prompt = opts[ :prompt ] || "Please enter the value for #{@name}"
17
- @regex = opts[ :regex ] || /^\w+$/
17
+ @regex = opts[ :regex ] || //
18
18
  @process = opts[ :process ] || nil
19
19
  end
20
20
 
@@ -37,3 +37,5 @@ class Linen::CLI::AmbiguousCommandError < Linen::CLI::AbstractAmbiguityError
37
37
  super
38
38
  end
39
39
  end
40
+
41
+ class Linen::WorkspaceError < RuntimeError ; end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ##############################################################
4
+ # Copyright 2007, LAIKA, Inc. #
5
+ # #
6
+ # Authors: #
7
+ # * Ben Bleything <bbleything@laika.com> #
8
+ ##############################################################
9
+
10
+ class Linen::Handler
11
+ # placeholder. This will eventually become the abstract
12
+ # class from which all handlers inherit.
13
+
14
+ def self::say( input )
15
+ raise NotImplementedError, "You must override say() in the handler"
16
+ end
17
+ end
@@ -7,7 +7,7 @@
7
7
  # * Ben Bleything <bbleything@laika.com> #
8
8
  ##############################################################
9
9
 
10
- class Linen::CLI
10
+ class Linen::CLI < Linen::Handler
11
11
  class << self
12
12
  attr_accessor :prompt
13
13
  end
@@ -63,7 +63,7 @@ class Linen::CLI
63
63
  end
64
64
 
65
65
 
66
- def self::start_loop
66
+ def self::start
67
67
  loop do
68
68
  begin
69
69
  input = Readline.readline( @prompt )
@@ -81,6 +81,11 @@ class Linen::CLI
81
81
  #######
82
82
  private
83
83
  #######
84
+
85
+ # def self::say( input )
86
+ # puts input
87
+ # end
88
+
84
89
 
85
90
  def self::canonicalize( input )
86
91
  begin
@@ -114,7 +119,11 @@ class Linen::CLI
114
119
 
115
120
  puts results.map { |arg, value|
116
121
  next unless value
117
- "#{arg}: #{value}"
122
+
123
+ output = value
124
+ output = value.join( ', ' ) if value.is_a? Array
125
+
126
+ "#{arg}: #{output}"
118
127
  }.join( "\n" )
119
128
 
120
129
  while input !~ /^(y|n)/i
@@ -8,6 +8,14 @@
8
8
  ##############################################################
9
9
 
10
10
  class Linen::Workspace
11
+ def self::register_handler( handler_class )
12
+ raise Linen::WorkspaceError,
13
+ "Can only register subclasses of Linen::Handler" unless
14
+ handler_class < Linen::Handler
15
+
16
+ @@handler = handler_class
17
+ end
18
+
11
19
  def set_value( name, value )
12
20
  # add getter
13
21
  (class << self ; self ; end).instance_eval {
@@ -26,4 +34,8 @@ class Linen::Workspace
26
34
  self.set_value k, v
27
35
  end
28
36
  end
37
+
38
+ def method_missing( *args )
39
+ @@handler.send( *args )
40
+ end
29
41
  end
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.4.0
6
+ version: 0.5.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:
@@ -35,9 +35,11 @@ files:
35
35
  - lib/indifferent_hash.rb
36
36
  - lib/linen
37
37
  - lib/linen/argument.rb
38
- - lib/linen/cli.rb
39
38
  - lib/linen/command.rb
40
39
  - lib/linen/exceptions.rb
40
+ - lib/linen/handler.rb
41
+ - lib/linen/handlers
42
+ - lib/linen/handlers/cli.rb
41
43
  - lib/linen/plugin.rb
42
44
  - lib/linen/plugin_registry.rb
43
45
  - lib/linen/workspace.rb