linen 0.7.0 → 0.8.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/LICENSE CHANGED
@@ -1,2 +1,28 @@
1
- Linen is copyright (c) 2007, LAIKA Inc. Linen is proprietary software
2
- and is not available for use outside LAIKA.
1
+ Copyright (c) 2007, LAIKA Inc. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are
5
+ met:
6
+
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the LAIKA, Inc nor the names of its contributors
15
+ may be used to endorse or promote products derived from this software
16
+ without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24
+ TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile CHANGED
@@ -1,15 +1,25 @@
1
- ##############################################################
2
- # Copyright 2007, LAIKA, Inc. #
3
- # #
4
- # Based heavily on Ben Bleything's Rakefile for plist, which #
5
- # is in turn based on Geoffrey Grosenbach's Rakefile for #
6
- # gruff. #
7
- # #
8
- # Includes whitespace-fixing task based on code from Typo. #
9
- # #
10
- # Authors: #
11
- # * Ben Bleything <bbleything@laika.com> #
12
- ##############################################################
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Based heavily on Ben Bleything's Rakefile for plist, which
4
+ # is in turn based on Geoffrey Grosenbach's Rakefile for
5
+ # gruff.
6
+ #
7
+ # Includes whitespace-fixing task based on code from Typo.
8
+ #
9
+ # == Authors
10
+ #
11
+ # * Ben Bleything <bbleything@laika.com>
12
+ #
13
+ # == Copyright
14
+ #
15
+ # Copyright (c) 2007 Laika, Inc.
16
+ #
17
+ # This code released under the terms of the BSD license.
18
+ #
19
+ # == Version
20
+ #
21
+ # $Id: Rakefile 273 2007-07-25 20:41:32Z bbleything $
22
+ #
13
23
 
14
24
  require 'fileutils'
15
25
  require 'rubygems'
@@ -18,24 +28,18 @@ require 'rake/testtask'
18
28
  require 'rake/rdoctask'
19
29
  require 'rake/packagetask'
20
30
  require 'rake/gempackagetask'
21
- require 'rake/contrib/rubyforgepublisher'
22
31
 
23
32
  $:.unshift(File.dirname(__FILE__) + "/lib")
24
33
  require 'linen'
25
34
 
26
35
  PKG_NAME = 'linen'
27
36
  PKG_VERSION = Linen::VERSION
28
- PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
29
-
30
- RELEASE_NAME = "REL #{PKG_VERSION}"
31
-
32
- RUBYFORGE_PROJECT = "linen"
33
- RUBYFORGE_USER = ENV['RUBYFORGE_USER']
34
37
 
35
38
  TEXT_FILES = %w( Rakefile README LICENSE )
36
39
  TEST_FILES = Dir.glob('test/test_*').delete_if { |item| item.include?( "\.svn" ) }
37
40
  LIB_FILES = Dir.glob('lib/**/*').delete_if { |item| item.include?( "\.svn" ) }
38
- RELEASE_FILES = TEXT_FILES + LIB_FILES + TEST_FILES
41
+ EXAMPLE_FILES = Dir.glob('examples/*.rb')
42
+ RELEASE_FILES = TEXT_FILES + LIB_FILES + TEST_FILES + EXAMPLE_FILES
39
43
 
40
44
  task :default => [ :test ]
41
45
 
@@ -138,8 +142,6 @@ Linen is a library which can be used to build a command-line interface for any p
138
142
  s.authors = "LAIKA, Inc."
139
143
  s.homepage = "http://opensource.laika.com"
140
144
 
141
- s.rubyforge_project = RUBYFORGE_PROJECT
142
-
143
145
  s.has_rdoc = true
144
146
 
145
147
  s.files = RELEASE_FILES
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Demonstrates more complex arguments and commands than
4
+ # math.rb, including a two-phase command (edit).
5
+ #
6
+ # == Authors
7
+ #
8
+ # * Ben Bleything <bbleything@laika.com>
9
+ #
10
+ # == Copyright
11
+ #
12
+ # Copyright (c) 2007 Laika, Inc.
13
+ #
14
+ # This code released under the terms of the BSD license.
15
+ #
16
+ # == Version
17
+ #
18
+ # $Id: host.rb 274 2007-07-25 21:06:42Z bbleything $
19
+ #
20
+
21
+ require 'rubygems'
22
+ require 'linen'
23
+ require 'ostruct'
24
+ require 'ping'
25
+ require 'socket'
26
+
27
+ class HostPlugin < Linen::Plugin
28
+ description "Inspect and check machines on your network."
29
+
30
+ argument :ip,
31
+ :prompt => 'Please enter the IP address: ',
32
+ :regex => /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/,
33
+ :process => lambda { |ip|
34
+ ip.split('.').each do |octet|
35
+ octet = octet.to_f
36
+
37
+ fail "#{ip} is not valid: #{octet.to_i} must be between 0 and 255." if octet < 0 or octet > 255
38
+ end
39
+
40
+ return ip
41
+ }
42
+
43
+ argument :hostname,
44
+ :prompt => 'Please enter the hostname: ',
45
+ :regex => /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/
46
+ # pattern yoinked from http://regexlib.com/REDetails.aspx?regexp_id=391
47
+
48
+ argument :mac,
49
+ :prompt => 'Please enter the MAC address: ',
50
+ :process => proc {|mac|
51
+ stripped_mac = mac.gsub( /:/, '' )
52
+ fail "MAC Address is too short." unless stripped_mac.length == 12
53
+ fail "MAC Address contains invalid characters." unless stripped_mac =~ /^[0-9a-f]*/i
54
+
55
+ return stripped_mac.scan( /../ ).join( ':' )
56
+ }
57
+
58
+ command :lookup do
59
+ help_message "Attempts to do a DNS lookup on the IP or hostname provided."
60
+
61
+ one_of :ip, :hostname
62
+
63
+ action do
64
+ ip_addr_info = Socket.getaddrinfo( ip, nil ) rescue nil
65
+ hn_addr_info = Socket.getaddrinfo( hostname, nil ) rescue nil
66
+
67
+ if ip_addr_info
68
+ say "IP address #{ip} has hostname #{ip_addr_info[0][2]}."
69
+ elsif hn_addr_info
70
+ say "Hostname '#{hostname}' has IP address #{hn_addr_info[0][3]}."
71
+ else
72
+ say "You said something I do not understand. I am sorry."
73
+ end
74
+ end
75
+ end
76
+
77
+ command :check do
78
+ help_message "Attempts to ping the IP or hostname provided."
79
+
80
+ one_of :ip, :hostname
81
+
82
+ require_confirmation
83
+
84
+ action do
85
+ to_check = ip || hostname
86
+
87
+ if Ping.pingecho( to_check, 5 )
88
+ say "Host #{to_check} is alive!"
89
+ else
90
+ say "Host #{to_check} appears to be dead :("
91
+ end
92
+ end
93
+ end
94
+
95
+ command :edit, :lookup_first => true do
96
+ help_message "Lets you pretend to change the host's IP and MAC addresses. Lookup by hostname."
97
+
98
+ lookup_by :hostname do |hostname|
99
+ out = OpenStruct.new
100
+ out.hostname = hostname
101
+ out.ip = Socket.getaddrinfo( hostname, nil )[0][3]
102
+
103
+ # yoinked this from a thread on ruby-talk about UUID generation
104
+ # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/242664
105
+ out.mac = ("%012x" % rand(1 << 12*4)).scan( /../ ).join( ':')
106
+
107
+ # return
108
+ out
109
+ end
110
+
111
+ inspect do
112
+ say "Hostname: #{hostname.hostname}"
113
+ say "IP Address: #{hostname.ip}"
114
+ say "MAC Address: #{hostname.mac}"
115
+ end
116
+
117
+ editable_attributes :ip, :mac
118
+
119
+ action do
120
+ say "If this was real, you would have just changed #{hostname.hostname}'s IP address to " +
121
+ "#{ip.empty? ? 'nothing' : ip} and its MAC address to #{mac.empty? ? 'nothing' : mac}. " +
122
+ "It's not real, though, so rest easy."
123
+ end
124
+ end
125
+ end
126
+
127
+ Linen::CLI.prompt = "host > "
128
+ Linen.start
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Demonstrates a simple plugin that does basic math.
4
+ #
5
+ # == Authors
6
+ #
7
+ # * Ben Bleything <bbleything@laika.com>
8
+ #
9
+ # == Copyright
10
+ #
11
+ # Copyright (c) 2007 Laika, Inc.
12
+ #
13
+ # This code released under the terms of the BSD license.
14
+ #
15
+ # == Version
16
+ #
17
+ # $Id: math.rb 274 2007-07-25 21:06:42Z bbleything $
18
+ #
19
+
20
+ require 'rubygems'
21
+ require 'linen'
22
+
23
+ class MathPlugin < Linen::Plugin
24
+ description "Perform simple mathematical operations. Currently supports addition, subtraction, multiplication, and division."
25
+
26
+ floating_point_regex = /^\d+(\.\d+)?$/
27
+
28
+ argument :lhs,
29
+ :prompt => 'Please enter the left-hand operand: ',
30
+ :regex => floating_point_regex,
31
+ :process => Proc.new {|i| i.to_f }
32
+
33
+ argument :rhs,
34
+ :prompt => 'Please enter the right-hand operand: ',
35
+ :regex => floating_point_regex,
36
+ :process => Proc.new {|i| i.to_f }
37
+
38
+ command :add do
39
+ help_message "Adds two operands. (lhs + rhs)"
40
+
41
+ required_arguments :lhs, :rhs
42
+
43
+ action do
44
+ say "#{lhs} + #{rhs} = #{lhs + rhs}"
45
+ end
46
+ end
47
+
48
+ command :subtract do
49
+ help_message "Subtracts the second operand from the first. (lhs - rhs)"
50
+
51
+ required_arguments :lhs, :rhs
52
+
53
+ action do
54
+ say "#{lhs} - #{rhs} = #{lhs - rhs}"
55
+ end
56
+ end
57
+
58
+ command :multiply do
59
+ help_message "Multiplies two operands. (lhs * rhs)"
60
+
61
+ required_arguments :lhs, :rhs
62
+
63
+ action do
64
+ say "#{lhs} * #{rhs} = #{lhs * rhs}"
65
+ end
66
+ end
67
+
68
+ command :divide do
69
+ help_message "Divides the first operand by the second. (lhs / rhs)"
70
+
71
+ required_arguments :lhs, :rhs
72
+
73
+ action do
74
+ say "#{lhs} / #{rhs} = #{lhs / rhs}"
75
+ end
76
+ end
77
+ end
78
+
79
+ Linen::CLI.prompt = "math > "
80
+ Linen.start
@@ -1,11 +1,22 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # Contains IndifferentHash, which can be deferenced by
4
+ # strings or symbols. It doesn't care, it's laid back.
5
+ #
6
+ # == Authors
7
+ #
8
+ # * Ben Bleything <bbleything@laika.com>
9
+ #
10
+ # == Copyright
11
+ #
12
+ # Copyright (c) 2007 Laika, Inc.
13
+ #
14
+ # This code released under the terms of the BSD license.
15
+ #
16
+ # == Version
17
+ #
18
+ # $Id: indifferent_hash.rb 274 2007-07-25 21:06:42Z bbleything $
19
+ #
9
20
 
10
21
  class IndifferentHash < Hash
11
22
  def []( key )
@@ -1,11 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # Linen is a framework for creating applications that use a command line
4
+ # interface. It features a simple plugin system, readline integration
5
+ # for history and completion, and other features.
6
+ #
7
+ # == Authors
8
+ #
9
+ # * Ben Bleything <bbleything@laika.com>
10
+ #
11
+ # == Copyright
12
+ #
13
+ # Copyright (c) 2007 Laika, Inc.
14
+ #
15
+ # This code released under the terms of the BSD license.
16
+ #
17
+ # == Version
18
+ #
19
+ # $Id: linen.rb 276 2007-07-25 21:14:39Z bbleything $
20
+ #
9
21
 
10
22
  ### External libraries
11
23
  require 'abbrev'
@@ -18,8 +30,8 @@ require 'string_extensions'
18
30
 
19
31
 
20
32
  module Linen
21
- VERSION = "0.7.0"
22
- SVNRev = %q$Rev: 231 $
33
+ VERSION = "0.8.0"
34
+ SVNRev = %q$Rev: 276 $
23
35
 
24
36
 
25
37
  def self::plugins
@@ -1,11 +1,22 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # Contains Linen::Argument, which encapsulates most of the
4
+ # argument parsing/processing logic.
5
+ #
6
+ # == Authors
7
+ #
8
+ # * Ben Bleything <bbleything@laika.com>
9
+ #
10
+ # == Copyright
11
+ #
12
+ # Copyright (c) 2007 Laika, Inc.
13
+ #
14
+ # This code released under the terms of the BSD license.
15
+ #
16
+ # == Version
17
+ #
18
+ # $Id: argument.rb 274 2007-07-25 21:06:42Z bbleything $
19
+ #
9
20
 
10
21
  class Linen::Plugin::Argument
11
22
  attr_reader :prompt
@@ -1,11 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # Defines a number of exceptions used throughout Linen.
4
+ #
5
+ # == Authors
6
+ #
7
+ # * Ben Bleything <bbleything@laika.com>
8
+ #
9
+ # == Copyright
10
+ #
11
+ # Copyright (c) 2007 Laika, Inc.
12
+ #
13
+ # This code released under the terms of the BSD license.
14
+ #
15
+ # == Version
16
+ #
17
+ # $Id: exceptions.rb 274 2007-07-25 21:06:42Z bbleything $
18
+ #
9
19
 
10
20
  class Linen::Plugin::ArgumentError < ArgumentError ; end
11
21
  class Linen::Plugin::PluginError < TypeError ; end
@@ -13,6 +23,9 @@ class Linen::Plugin::PluginError < TypeError ; end
13
23
  class Linen::CLI::PluginNotFoundError < NameError ; end
14
24
  class Linen::CLI::CommandNotFoundError < NameError ; end
15
25
 
26
+ ### ambiguity errors can sometimes carry a payload of possible
27
+ ### completions for the ambiguous input; those are stored in the
28
+ ### exception when it's raised.
16
29
  class Linen::CLI::AbstractAmbiguityError < NameError
17
30
  attr_accessor :candidates, :input
18
31
 
@@ -1,11 +1,22 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # The abstract handler from which all other handlers must
4
+ # inherit.
5
+ #
6
+ # == Authors
7
+ #
8
+ # * Ben Bleything <bbleything@laika.com>
9
+ #
10
+ # == Copyright
11
+ #
12
+ # Copyright (c) 2007 Laika, Inc.
13
+ #
14
+ # This code released under the terms of the BSD license.
15
+ #
16
+ # == Version
17
+ #
18
+ # $Id: handler.rb 274 2007-07-25 21:06:42Z bbleything $
19
+ #
9
20
 
10
21
  class Linen::Handler
11
22
  def self::say( input = '' )
@@ -1,11 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # The CLI handler. This uses Readline and friends to provide
4
+ # a command-line-like interface to the loaded plugins. It is
5
+ # the default handler.
6
+ #
7
+ # == Authors
8
+ #
9
+ # * Ben Bleything <bbleything@laika.com>
10
+ #
11
+ # == Copyright
12
+ #
13
+ # Copyright (c) 2007 Laika, Inc.
14
+ #
15
+ # This code released under the terms of the BSD license.
16
+ #
17
+ # == Version
18
+ #
19
+ # $Id: cli.rb 274 2007-07-25 21:06:42Z bbleything $
20
+ #
9
21
 
10
22
  class Linen::CLI < Linen::Handler
11
23
  class << self
@@ -1,11 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # Defines Linen::Plugin, which defines the structure of
4
+ # a plugin, as well as the DSL used to write a plugin.
5
+ #
6
+ # Also includes some "meta-functions", like help.
7
+ #
8
+ # == Authors
9
+ #
10
+ # * Ben Bleything <bbleything@laika.com>
11
+ #
12
+ # == Copyright
13
+ #
14
+ # Copyright (c) 2007 Laika, Inc.
15
+ #
16
+ # This code released under the terms of the BSD license.
17
+ #
18
+ # == Version
19
+ #
20
+ # $Id: plugin.rb 274 2007-07-25 21:06:42Z bbleything $
21
+ #
9
22
 
10
23
  class Linen::Plugin
11
24
  class << self
@@ -1,11 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # An array-like register of all loaded plugins.
4
+ #
5
+ # == Authors
6
+ #
7
+ # * Ben Bleything <bbleything@laika.com>
8
+ #
9
+ # == Copyright
10
+ #
11
+ # Copyright (c) 2007 Laika, Inc.
12
+ #
13
+ # This code released under the terms of the BSD license.
14
+ #
15
+ # == Version
16
+ #
17
+ # $Id: plugin_registry.rb 274 2007-07-25 21:06:42Z bbleything $
18
+ #
9
19
 
10
20
  require 'singleton'
11
21
 
@@ -1,11 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # A simple, single-phased command.
4
+ #
5
+ # == Authors
6
+ #
7
+ # * Ben Bleything <bbleything@laika.com>
8
+ #
9
+ # == Copyright
10
+ #
11
+ # Copyright (c) 2007 Laika, Inc.
12
+ #
13
+ # This code released under the terms of the BSD license.
14
+ #
15
+ # == Version
16
+ #
17
+ # $Id: simple_command.rb 274 2007-07-25 21:06:42Z bbleything $
18
+ #
9
19
 
10
20
  class Linen::Plugin::SimpleCommand
11
21
  attr_reader :name
@@ -1,11 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # A two-phase command, commonly used for editing data.
4
+ #
5
+ # == Authors
6
+ #
7
+ # * Ben Bleything <bbleything@laika.com>
8
+ #
9
+ # == Copyright
10
+ #
11
+ # Copyright (c) 2007 Laika, Inc.
12
+ #
13
+ # This code released under the terms of the BSD license.
14
+ #
15
+ # == Version
16
+ #
17
+ # $Id: two_phase_command.rb 274 2007-07-25 21:06:42Z bbleything $
18
+ #
9
19
 
10
20
  class Linen::Plugin::TwoPhaseCommand
11
21
  attr_reader :name, :editable_attrs, :lookup_attr
@@ -1,11 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # The semi-specialized binding in which commands are executed.
4
+ #
5
+ # == Authors
6
+ #
7
+ # * Ben Bleything <bbleything@laika.com>
8
+ #
9
+ # == Copyright
10
+ #
11
+ # Copyright (c) 2007 Laika, Inc.
12
+ #
13
+ # This code released under the terms of the BSD license.
14
+ #
15
+ # == Version
16
+ #
17
+ # $Id: workspace.rb 274 2007-07-25 21:06:42Z bbleything $
18
+ #
9
19
 
10
20
  class Linen::Workspace
11
21
  def self::register_handler( handler_class )
@@ -1,15 +1,25 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- ##############################################################
4
- # Copyright 2007, LAIKA, Inc. #
5
- # #
6
- # Authors: #
7
- # * Ben Bleything <bbleything@laika.com> #
8
- ##############################################################
2
+ #
3
+ # Adds String#wrap, which can be used to wrap at a particular column.
4
+ #
5
+ # == Authors
6
+ #
7
+ # * Ben Bleything <bbleything@laika.com>
8
+ #
9
+ # == Copyright
10
+ #
11
+ # Copyright (c) 2007 Laika, Inc.
12
+ #
13
+ # This code released under the terms of the BSD license.
14
+ #
15
+ # == Version
16
+ #
17
+ # $Id: string_extensions.rb 274 2007-07-25 21:06:42Z bbleything $
18
+ #
9
19
 
10
20
  class String
21
+ ### Wraps a string at the given column (or 72, if none provided)
11
22
  def wrap(line_width = 72)
12
23
  self.gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").chomp
13
24
  end
14
25
  end
15
-
metadata CHANGED
@@ -3,14 +3,14 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: linen
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.0
6
+ version: 0.8.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:
10
10
  - lib
11
11
  email:
12
12
  homepage: http://opensource.laika.com
13
- rubyforge_project: linen
13
+ rubyforge_project:
14
14
  description: Linen is a library which can be used to build a command-line interface for any purpose. It features a plugin architecture to specify new tasks, Readline support, history, and more.
15
15
  autorequire: linen
16
16
  default_executable:
@@ -49,6 +49,8 @@ files:
49
49
  - test/test_cli.rb
50
50
  - test/test_indifferent_hash.rb
51
51
  - test/test_plugins.rb
52
+ - examples/host.rb
53
+ - examples/math.rb
52
54
  test_files:
53
55
  - test/test_cli.rb
54
56
  - test/test_indifferent_hash.rb