bundler 1.0.0.beta.5 → 1.0.0.beta.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

@@ -150,7 +150,7 @@ class Thor
150
150
  return nil # User set value to nil
151
151
  elsif option.string? && !option.required?
152
152
  # Return the default if there is one, else the human name
153
- return option.default || option.human_name
153
+ return option.lazy_default || option.default || option.human_name
154
154
  else
155
155
  raise MalformattedArgumentError, "No value provided for option '#{switch}'"
156
156
  end
@@ -1,5 +1,4 @@
1
1
  require 'rbconfig'
2
- require 'thor/shell/color'
3
2
 
4
3
  class Thor
5
4
  module Base
@@ -7,7 +6,9 @@ class Thor
7
6
  # it will use a colored log, otherwise it will use a basic one without color.
8
7
  #
9
8
  def self.shell
10
- @shell ||= if Config::CONFIG['host_os'] =~ /mswin|mingw/
9
+ @shell ||= if ENV['THOR_SHELL'] && ENV['THOR_SHELL'].size > 0
10
+ Thor::Shell.const_get(ENV['THOR_SHELL'])
11
+ elsif Config::CONFIG['host_os'] =~ /mswin|mingw/
11
12
  Thor::Shell::Basic
12
13
  else
13
14
  Thor::Shell::Color
@@ -24,6 +25,10 @@ class Thor
24
25
  module Shell
25
26
  SHELL_DELEGATED_METHODS = [:ask, :yes?, :no?, :say, :say_status, :print_table]
26
27
 
28
+ autoload :Basic, 'thor/shell/basic'
29
+ autoload :Color, 'thor/shell/color'
30
+ autoload :HTML, 'thor/shell/HTML'
31
+
27
32
  # Add shell to initialize config values.
28
33
  #
29
34
  # ==== Configuration
@@ -42,8 +42,8 @@ class Thor
42
42
  $stdout.puts(message)
43
43
  else
44
44
  $stdout.print(message)
45
- $stdout.flush
46
45
  end
46
+ $stdout.flush
47
47
  end
48
48
 
49
49
  # Say a status with the given color and appends the message. Since this
@@ -81,16 +81,20 @@ class Thor
81
81
  # Array[Array[String, String, ...]]
82
82
  #
83
83
  # ==== Options
84
- # ident<Integer>:: Ident the first column by ident value.
84
+ # ident<Integer>:: Indent the first column by ident value.
85
+ # colwidth<Integer>:: Force the first column to colwidth spaces wide.
85
86
  #
86
87
  def print_table(table, options={})
87
88
  return if table.empty?
88
89
 
89
- formats, ident = [], options[:ident].to_i
90
+ formats, ident, colwidth = [], options[:ident].to_i, options[:colwidth]
90
91
  options[:truncate] = terminal_width if options[:truncate] == true
91
92
 
92
- 0.upto(table.first.length - 2) do |i|
93
- maxima = table.max{ |a,b| a[i].size <=> b[i].size }[i].size
93
+ formats << "%-#{colwidth + 2}s" if colwidth
94
+ start = colwidth ? 1 : 0
95
+
96
+ start.upto(table.first.length - 2) do |i|
97
+ maxima ||= table.max{|a,b| a[i].size <=> b[i].size }[i].size
94
98
  formats << "%-#{maxima + 2}s"
95
99
  end
96
100
 
@@ -0,0 +1,121 @@
1
+ require 'thor/shell/basic'
2
+
3
+ class Thor
4
+ module Shell
5
+ # Inherit from Thor::Shell::Basic and add set_color behavior. Check
6
+ # Thor::Shell::Basic to see all available methods.
7
+ #
8
+ class HTML < Basic
9
+ # The start of an HTML bold sequence.
10
+ BOLD = "<strong>"
11
+ # The end of an HTML bold sequence.
12
+ END_BOLD = "</strong>"
13
+
14
+ # Embed in a String to clear previous color selection.
15
+ CLEAR = "</span>"
16
+
17
+ # Set the terminal's foreground HTML color to black.
18
+ BLACK = '<span style="color: black;">'
19
+ # Set the terminal's foreground HTML color to red.
20
+ RED = '<span style="color: red;">'
21
+ # Set the terminal's foreground HTML color to green.
22
+ GREEN = '<span style="color: green;">'
23
+ # Set the terminal's foreground HTML color to yellow.
24
+ YELLOW = '<span style="color: yellow;">'
25
+ # Set the terminal's foreground HTML color to blue.
26
+ BLUE = '<span style="color: blue;">'
27
+ # Set the terminal's foreground HTML color to magenta.
28
+ MAGENTA = '<span style="color: magenta;">'
29
+ # Set the terminal's foreground HTML color to cyan.
30
+ CYAN = '<span style="color: cyan;">'
31
+ # Set the terminal's foreground HTML color to white.
32
+ WHITE = '<span style="color: white;">'
33
+
34
+ # Set the terminal's background HTML color to black.
35
+ ON_BLACK = '<span style="background-color: black">'
36
+ # Set the terminal's background HTML color to red.
37
+ ON_RED = '<span style="background-color: red">'
38
+ # Set the terminal's background HTML color to green.
39
+ ON_GREEN = '<span style="background-color: green">'
40
+ # Set the terminal's background HTML color to yellow.
41
+ ON_YELLOW = '<span style="background-color: yellow">'
42
+ # Set the terminal's background HTML color to blue.
43
+ ON_BLUE = '<span style="background-color: blue">'
44
+ # Set the terminal's background HTML color to magenta.
45
+ ON_MAGENTA = '<span style="background-color: magenta">'
46
+ # Set the terminal's background HTML color to cyan.
47
+ ON_CYAN = '<span style="background-color: cyan">'
48
+ # Set the terminal's background HTML color to white.
49
+ ON_WHITE = '<span style="background-color: white">'
50
+
51
+ # Set color by using a string or one of the defined constants. If a third
52
+ # option is set to true, it also adds bold to the string. This is based
53
+ # on Highline implementation and it automatically appends CLEAR to the end
54
+ # of the returned String.
55
+ #
56
+ def set_color(string, color, bold=false)
57
+ color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
58
+ bold, end_bold = bold ? [BOLD, END_BOLD] : ['', '']
59
+ "#{bold}#{color}#{string}#{CLEAR}#{end_bold}"
60
+ end
61
+
62
+ # Ask something to the user and receives a response.
63
+ #
64
+ # ==== Example
65
+ # ask("What is your name?")
66
+ #
67
+ # TODO: Implement #ask for Thor::Shell::HTML
68
+ def ask(statement, color=nil)
69
+ raise NotImplementedError, "Implement #ask for Thor::Shell::HTML"
70
+ end
71
+
72
+ protected
73
+
74
+ # Overwrite show_diff to show diff with colors if Diff::LCS is
75
+ # available.
76
+ #
77
+ def show_diff(destination, content) #:nodoc:
78
+ if diff_lcs_loaded? && ENV['THOR_DIFF'].nil? && ENV['RAILS_DIFF'].nil?
79
+ actual = File.binread(destination).to_s.split("\n")
80
+ content = content.to_s.split("\n")
81
+
82
+ Diff::LCS.sdiff(actual, content).each do |diff|
83
+ output_diff_line(diff)
84
+ end
85
+ else
86
+ super
87
+ end
88
+ end
89
+
90
+ def output_diff_line(diff) #:nodoc:
91
+ case diff.action
92
+ when '-'
93
+ say "- #{diff.old_element.chomp}", :red, true
94
+ when '+'
95
+ say "+ #{diff.new_element.chomp}", :green, true
96
+ when '!'
97
+ say "- #{diff.old_element.chomp}", :red, true
98
+ say "+ #{diff.new_element.chomp}", :green, true
99
+ else
100
+ say " #{diff.old_element.chomp}", nil, true
101
+ end
102
+ end
103
+
104
+ # Check if Diff::LCS is loaded. If it is, use it to create pretty output
105
+ # for diff.
106
+ #
107
+ def diff_lcs_loaded? #:nodoc:
108
+ return true if defined?(Diff::LCS)
109
+ return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
110
+
111
+ @diff_lcs_loaded = begin
112
+ require 'diff/lcs'
113
+ true
114
+ rescue LoadError
115
+ false
116
+ end
117
+ end
118
+
119
+ end
120
+ end
121
+ end
@@ -2,21 +2,6 @@ class Thor
2
2
  class Task < Struct.new(:name, :description, :long_description, :usage, :options)
3
3
  FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/
4
4
 
5
- # A dynamic task that handles method missing scenarios.
6
- class Dynamic < Task
7
- def initialize(name, options=nil)
8
- super(name.to_s, "A dynamically-generated task", name.to_s, name.to_s, options)
9
- end
10
-
11
- def run(instance, args=[])
12
- if (instance.methods & [name.to_s, name.to_sym]).empty?
13
- super
14
- else
15
- instance.class.handle_no_task_error(name)
16
- end
17
- end
18
- end
19
-
20
5
  def initialize(name, description, long_description, usage, options=nil)
21
6
  super(name.to_s, description, long_description, usage, options || {})
22
7
  end
@@ -26,6 +11,10 @@ class Thor
26
11
  self.options = other.options.dup if other.options
27
12
  end
28
13
 
14
+ def hidden?
15
+ false
16
+ end
17
+
29
18
  # By default, a task invokes a method in the thor class. You can change this
30
19
  # implementation to create custom tasks.
31
20
  def run(instance, args=[])
@@ -41,16 +30,15 @@ class Thor
41
30
 
42
31
  # Returns the formatted usage by injecting given required arguments
43
32
  # and required options into the given usage.
44
- def formatted_usage(klass, namespace=true)
45
- namespace = klass.namespace unless namespace == false
46
-
47
- # Add namespace
48
- formatted = if namespace
49
- "#{namespace.gsub(/^(default|thor:runner:)/,'')}:"
50
- else
51
- ""
33
+ def formatted_usage(klass, namespace = true, subcommand = false)
34
+ if namespace
35
+ namespace = klass.namespace
36
+ formatted = "#{namespace.gsub(/^(default)/,'')}:"
37
+ formatted.sub!(/.$/, ' ') if subcommand
52
38
  end
53
39
 
40
+ formatted ||= ""
41
+
54
42
  # Add usage with required arguments
55
43
  formatted << if klass && !klass.arguments.empty?
56
44
  usage.to_s.gsub(/^#{name}/) do |match|
@@ -67,36 +55,60 @@ class Thor
67
55
  formatted.strip
68
56
  end
69
57
 
70
- protected
58
+ protected
71
59
 
72
- def not_debugging?(instance)
73
- !(instance.class.respond_to?(:debugging) && instance.class.debugging)
74
- end
60
+ def not_debugging?(instance)
61
+ !(instance.class.respond_to?(:debugging) && instance.class.debugging)
62
+ end
75
63
 
76
- def required_options
77
- @required_options ||= options.map{ |_, o| o.usage if o.required? }.compact.sort.join(" ")
78
- end
64
+ def required_options
65
+ @required_options ||= options.map{ |_, o| o.usage if o.required? }.compact.sort.join(" ")
66
+ end
79
67
 
80
- # Given a target, checks if this class name is not a private/protected method.
81
- def public_method?(instance) #:nodoc:
82
- collection = instance.private_methods + instance.protected_methods
83
- (collection & [name.to_s, name.to_sym]).empty?
84
- end
68
+ # Given a target, checks if this class name is not a private/protected method.
69
+ def public_method?(instance) #:nodoc:
70
+ collection = instance.private_methods + instance.protected_methods
71
+ (collection & [name.to_s, name.to_sym]).empty?
72
+ end
85
73
 
86
- def sans_backtrace(backtrace, caller) #:nodoc:
87
- saned = backtrace.reject { |frame| frame =~ FILE_REGEXP }
88
- saned -= caller
89
- end
74
+ def sans_backtrace(backtrace, caller) #:nodoc:
75
+ saned = backtrace.reject { |frame| frame =~ FILE_REGEXP }
76
+ saned -= caller
77
+ end
90
78
 
91
- def handle_argument_error?(instance, error, caller)
92
- not_debugging?(instance) && error.message =~ /wrong number of arguments/ &&
93
- sans_backtrace(error.backtrace, caller).empty?
79
+ def handle_argument_error?(instance, error, caller)
80
+ not_debugging?(instance) && error.message =~ /wrong number of arguments/ && begin
81
+ saned = sans_backtrace(error.backtrace, caller)
82
+ # Ruby 1.9 always include the called method in the backtrace
83
+ saned.empty? || (saned.size == 1 && RUBY_VERSION >= "1.9")
94
84
  end
85
+ end
95
86
 
96
- def handle_no_method_error?(instance, error, caller)
97
- not_debugging?(instance) &&
98
- error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/
99
- end
87
+ def handle_no_method_error?(instance, error, caller)
88
+ not_debugging?(instance) &&
89
+ error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/
90
+ end
91
+ end
92
+
93
+ # A task that is hidden in help messages but still invocable.
94
+ class HiddenTask < Task
95
+ def hidden?
96
+ true
97
+ end
98
+ end
99
+
100
+ # A dynamic task that handles method missing scenarios.
101
+ class DynamicTask < Task
102
+ def initialize(name, options=nil)
103
+ super(name.to_s, "A dynamically-generated task", name.to_s, name.to_s, options)
104
+ end
100
105
 
106
+ def run(instance, args=[])
107
+ if (instance.methods & [name.to_s, name.to_sym]).empty?
108
+ super
109
+ else
110
+ instance.class.handle_no_task_error(name)
111
+ end
112
+ end
101
113
  end
102
114
  end
@@ -1,3 +1,3 @@
1
1
  class Thor
2
- VERSION = "0.13.6".freeze
2
+ VERSION = "0.13.8".freeze
3
3
  end
@@ -2,5 +2,5 @@ module Bundler
2
2
  # We're doing this because we might write tests that deal
3
3
  # with other versions of bundler and we are unsure how to
4
4
  # handle this better.
5
- VERSION = "1.0.0.beta.5" unless defined?(::Bundler::VERSION)
6
- end
5
+ VERSION = "1.0.0.beta.8" unless defined?(::Bundler::VERSION)
6
+ end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 5
11
- version: 1.0.0.beta.5
10
+ - 8
11
+ version: 1.0.0.beta.8
12
12
  platform: ruby
13
13
  authors:
14
14
  - Carl Lerche
@@ -18,13 +18,14 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-07-12 00:00:00 -07:00
21
+ date: 2010-07-20 00:00:00 -07:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: rspec
26
26
  prerelease: false
27
27
  requirement: &id001 !ruby/object:Gem::Requirement
28
+ none: false
28
29
  requirements:
29
30
  - - ">="
30
31
  - !ruby/object:Gem::Version
@@ -79,6 +80,7 @@ files:
79
80
  - lib/bundler/vendor/thor/parser.rb
80
81
  - lib/bundler/vendor/thor/shell/basic.rb
81
82
  - lib/bundler/vendor/thor/shell/color.rb
83
+ - lib/bundler/vendor/thor/shell/html.rb
82
84
  - lib/bundler/vendor/thor/shell.rb
83
85
  - lib/bundler/vendor/thor/task.rb
84
86
  - lib/bundler/vendor/thor/util.rb
@@ -101,6 +103,7 @@ rdoc_options: []
101
103
  require_paths:
102
104
  - lib
103
105
  required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
104
107
  requirements:
105
108
  - - ">="
106
109
  - !ruby/object:Gem::Version
@@ -108,6 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
111
  - 0
109
112
  version: "0"
110
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
111
115
  requirements:
112
116
  - - ">="
113
117
  - !ruby/object:Gem::Version
@@ -119,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
123
  requirements: []
120
124
 
121
125
  rubyforge_project: bundler
122
- rubygems_version: 1.3.6
126
+ rubygems_version: 1.3.7
123
127
  signing_key:
124
128
  specification_version: 3
125
129
  summary: The best way to manage your application's dependencies