daemon-kit 0.1.8rc2 → 0.1.8rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/Rakefile +1 -0
  2. data/daemon-kit.gemspec +36 -36
  3. data/lib/daemon_kit.rb +1 -1
  4. data/lib/daemon_kit/amqp.rb +1 -0
  5. data/lib/daemon_kit/cron.rb +16 -0
  6. data/lib/daemon_kit/deployment/capistrano.rb +34 -0
  7. data/lib/daemon_kit/error_handlers/hoptoad.rb +8 -2
  8. data/lib/daemon_kit/generators.rb +1 -1
  9. data/lib/daemon_kit/generators/base.rb +1 -1
  10. data/lib/daemon_kit/ruote_participants.rb +7 -1
  11. data/lib/daemon_kit/ruote_workitem.rb +30 -20
  12. data/lib/daemon_kit/tasks/environment.rake +1 -0
  13. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/CHANGELOG.rdoc +9 -0
  14. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/LICENSE +0 -0
  15. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/README.rdoc +65 -2
  16. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/Thorfile +14 -9
  17. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor.rb +10 -8
  18. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions.rb +34 -12
  19. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/create_file.rb +0 -0
  20. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/directory.rb +0 -0
  21. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/empty_directory.rb +0 -0
  22. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/file_manipulation.rb +1 -1
  23. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/actions/inject_into_file.rb +9 -6
  24. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/base.rb +45 -20
  25. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/core_ext/file_binary_read.rb +0 -0
  26. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/core_ext/hash_with_indifferent_access.rb +0 -0
  27. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/core_ext/ordered_hash.rb +0 -0
  28. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/error.rb +3 -0
  29. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/group.rb +21 -21
  30. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/invocation.rb +19 -17
  31. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/parser.rb +0 -0
  32. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/parser/argument.rb +0 -0
  33. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/parser/arguments.rb +9 -4
  34. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/parser/option.rb +0 -4
  35. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/parser/options.rb +41 -14
  36. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/rake_compat.rb +0 -0
  37. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/runner.rb +20 -9
  38. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/shell.rb +8 -3
  39. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/shell/basic.rb +0 -0
  40. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/shell/color.rb +0 -0
  41. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/task.rb +24 -33
  42. data/lib/daemon_kit/vendor/{thor-0.12.3 → thor-0.13.6}/lib/thor/util.rb +9 -18
  43. data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/version.rb +3 -0
  44. data/lib/generators/daemon_kit/amqp/amqp_generator.rb +1 -1
  45. data/lib/generators/daemon_kit/amqp/templates/config/pre-daemonize/amqp.rb +1 -1
  46. data/lib/generators/daemon_kit/app/app_generator.rb +1 -1
  47. data/lib/generators/daemon_kit/app/templates/README.tt +58 -0
  48. data/lib/generators/daemon_kit/capistrano/capistrano_generator.rb +5 -0
  49. data/lib/generators/daemon_kit/cron/cron_generator.rb +1 -1
  50. data/lib/generators/daemon_kit/cron/templates/config/pre-daemonize/cron.rb +1 -1
  51. data/lib/generators/daemon_kit/nanite_agent/nanite_agent_generator.rb +1 -1
  52. data/lib/generators/daemon_kit/nanite_agent/templates/config/pre-daemonize/nanite_agent.rb +1 -1
  53. data/lib/generators/daemon_kit/ruote/ruote_generator.rb +2 -2
  54. data/lib/generators/daemon_kit/ruote/templates/config/pre-daemonize/ruote.rb +2 -2
  55. data/lib/generators/daemon_kit/xmpp/templates/config/pre-daemonize/xmpp.rb +1 -1
  56. data/lib/generators/daemon_kit/xmpp/xmpp_generator.rb +1 -1
  57. data/tasks/rspec.rake +6 -7
  58. metadata +77 -49
  59. data/lib/daemon_kit/vendor/thor-0.12.3/lib/thor/version.rb +0 -3
  60. data/lib/generators/daemon_kit/app/templates/README +0 -48
@@ -19,6 +19,9 @@ class Thor
19
19
  class InvocationError < Error
20
20
  end
21
21
 
22
+ class UnknownArgumentError < Error
23
+ end
24
+
22
25
  class RequiredArgumentMissingError < InvocationError
23
26
  end
24
27
 
@@ -1,8 +1,9 @@
1
+ require 'thor/base'
2
+
1
3
  # Thor has a special class called Thor::Group. The main difference to Thor class
2
4
  # is that it invokes all tasks at once. It also include some methods that allows
3
5
  # invocations to be done at the class method, which are not available to Thor
4
6
  # tasks.
5
- #
6
7
  class Thor::Group
7
8
  class << self
8
9
  # The descrition for this Thor::Group. If none is provided, but a source root
@@ -24,8 +25,8 @@ class Thor::Group
24
25
  # Start works differently in Thor::Group, it simply invokes all tasks
25
26
  # inside the class.
26
27
  #
27
- def start(given_args=ARGV, config={})
28
- super do
28
+ def start(original_args=ARGV, config={})
29
+ super do |given_args|
29
30
  if Thor::HELP_MAPPINGS.include?(given_args.first)
30
31
  help(config[:shell])
31
32
  return
@@ -218,14 +219,16 @@ class Thor::Group
218
219
  [item]
219
220
  end
220
221
 
222
+ def handle_argument_error(task, error) #:nodoc:
223
+ raise error, "#{task.name.inspect} was called incorrectly. Are you sure it has arity equals to 0?"
224
+ end
225
+
221
226
  protected
222
227
 
223
228
  # The banner for this class. You can customize it if you are invoking the
224
229
  # thor class by another ways which is not the Thor::Runner.
225
- #
226
230
  def banner
227
- base = $thor_runner ? "thor" : File.basename($0.split(" ").first)
228
- "#{base} #{self_task.formatted_usage(self, false)}"
231
+ "#{banner_base} #{self_task.formatted_usage(self, false)}"
229
232
  end
230
233
 
231
234
  # Represents the whole class as a task.
@@ -250,22 +253,19 @@ class Thor::Group
250
253
  # Shortcut to invoke with padding and block handling. Use internally by
251
254
  # invoke and invoke_from_option class methods.
252
255
  def _invoke_for_class_method(klass, task=nil, *args, &block) #:nodoc:
253
- shell.padding += 1
254
-
255
- result = if block_given?
256
- case block.arity
257
- when 3
258
- block.call(self, klass, task)
259
- when 2
260
- block.call(self, klass)
261
- when 1
262
- instance_exec(klass, &block)
256
+ with_padding do
257
+ if block
258
+ case block.arity
259
+ when 3
260
+ block.call(self, klass, task)
261
+ when 2
262
+ block.call(self, klass)
263
+ when 1
264
+ instance_exec(klass, &block)
265
+ end
266
+ else
267
+ invoke klass, task, *args
263
268
  end
264
- else
265
- invoke klass, task, *args
266
269
  end
267
-
268
- shell.padding -= 1
269
- result
270
270
  end
271
271
  end
@@ -5,21 +5,20 @@ class Thor
5
5
  end
6
6
 
7
7
  module ClassMethods
8
- # Prepare for class methods invocations. This method must return a klass to
9
- # have the invoked class options showed in help messages in generators.
10
- #
8
+ # This method is responsible for receiving a name and find the proper
9
+ # class and task for it. The key is an optional parameter which is
10
+ # available only in class methods invocations (i.e. in Thor::Group).
11
11
  def prepare_for_invocation(key, name) #:nodoc:
12
12
  case name
13
13
  when Symbol, String
14
- Thor::Util.namespace_to_thor_class_and_task(name.to_s, false)
14
+ Thor::Util.find_class_and_task_by_namespace(name.to_s, !key)
15
15
  else
16
16
  name
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
- # Make initializer aware of invocations and the initializer proc.
22
- #
21
+ # Make initializer aware of invocations and the initialization args.
23
22
  def initialize(args=[], options={}, config={}, &block) #:nodoc:
24
23
  @_invocations = config[:invocations] || Hash.new { |h,k| h[k] = [] }
25
24
  @_initializer = [ args, options, config ]
@@ -34,6 +33,8 @@ class Thor
34
33
  # the task to be invoked, if none is given, the same values used to
35
34
  # initialize the invoker are used to initialize the invoked.
36
35
  #
36
+ # When no name is given, it will invoke the default task of the current class.
37
+ #
37
38
  # ==== Examples
38
39
  #
39
40
  # class A < Thor
@@ -92,9 +93,9 @@ class Thor
92
93
  #
93
94
  # invoke Rspec::RR, [], :style => :foo
94
95
  #
95
- def invoke(name=nil, task=nil, args=nil, opts=nil, config=nil)
96
- task, args, opts, config = nil, task, args, opts if task.nil? || task.is_a?(Array)
97
- args, opts, config = nil, args, opts if args.is_a?(Hash)
96
+ def invoke(name=nil, *args)
97
+ args.unshift(nil) if Array === args.first || NilClass === args.first
98
+ task, args, opts, config = args
98
99
 
99
100
  object, task = _prepare_for_invocation(name, task)
100
101
  klass, instance = _initialize_klass_with_initializer(object, args, opts, config)
@@ -118,18 +119,21 @@ class Thor
118
119
  end
119
120
  end
120
121
 
122
+ # Invokes using shell padding.
123
+ def invoke_with_padding(*args)
124
+ with_padding { invoke(*args) }
125
+ end
126
+
121
127
  protected
122
128
 
123
129
  # Configuration values that are shared between invocations.
124
- #
125
130
  def _shared_configuration #:nodoc:
126
131
  { :invocations => @_invocations }
127
132
  end
128
133
 
129
- # Prepare for invocation in the instance level. In this case, we have to
130
- # take into account that a just a task name from the current class was
131
- # given or even a Thor::Task object.
132
- #
134
+ # This method can receive several different types of arguments and it's then
135
+ # responsible to normalize them by returning the object where the task should
136
+ # be invoked and a Thor::Task object.
133
137
  def _prepare_for_invocation(name, sent_task=nil) #:nodoc:
134
138
  if name.is_a?(Thor::Task)
135
139
  task = name
@@ -147,18 +151,16 @@ class Thor
147
151
 
148
152
  # Check if the object given is a Thor class object and get a task object
149
153
  # for it.
150
- #
151
154
  def _validate_task(object, task) #:nodoc:
152
155
  klass = object.is_a?(Class) ? object : object.class
153
156
  raise "Expected Thor class, got #{klass}" unless klass <= Thor::Base
154
157
 
155
- task ||= klass.default_task if klass <= Thor
158
+ task ||= klass.default_task if klass.respond_to?(:default_task)
156
159
  task = klass.all_tasks[task.to_s] || Thor::Task::Dynamic.new(task) if task && !task.is_a?(Thor::Task)
157
160
  task
158
161
  end
159
162
 
160
163
  # Initialize klass using values stored in the @_initializer.
161
- #
162
164
  def _initialize_klass_with_initializer(object, args, opts, config) #:nodoc:
163
165
  if object.is_a?(Class)
164
166
  klass = object
@@ -16,8 +16,9 @@ class Thor
16
16
  return arguments, args[Range.new(arguments.size, -1)]
17
17
  end
18
18
 
19
- def self.parse(base, args)
20
- new(base).parse(args)
19
+ def self.parse(*args)
20
+ to_parse = args.pop
21
+ new(*args).parse(to_parse)
21
22
  end
22
23
 
23
24
  # Takes an array of Thor::Argument objects.
@@ -50,6 +51,10 @@ class Thor
50
51
 
51
52
  private
52
53
 
54
+ def last?
55
+ @pile.empty?
56
+ end
57
+
53
58
  def peek
54
59
  @pile.first
55
60
  end
@@ -116,7 +121,7 @@ class Thor
116
121
  return shift if peek.is_a?(Numeric)
117
122
 
118
123
  unless peek =~ NUMERIC && $& == peek
119
- raise MalformattedArgumentError, "expected numeric value for '#{name}'; got #{peek.inspect}"
124
+ raise MalformattedArgumentError, "Expected numeric value for '#{name}'; got #{peek.inspect}"
120
125
  end
121
126
 
122
127
  $&.index('.') ? shift.to_f : shift.to_i
@@ -137,7 +142,7 @@ class Thor
137
142
  end.join("', '")
138
143
 
139
144
  class_name = self.class.name.split('::').last.downcase
140
- raise RequiredArgumentMissingError, "no value provided for required #{class_name} '#{names}'"
145
+ raise RequiredArgumentMissingError, "No value provided for required #{class_name} '#{names}'"
141
146
  end
142
147
  end
143
148
 
@@ -55,10 +55,6 @@ class Thor
55
55
  value
56
56
  elsif required = (value == :required)
57
57
  :string
58
- elsif value == :optional
59
- # TODO Remove this warning in the future.
60
- warn "Optional type is deprecated. Choose :boolean or :string instead. Assumed to be :boolean."
61
- :boolean
62
58
  end
63
59
  when TrueClass, FalseClass
64
60
  :boolean
@@ -3,14 +3,13 @@ class Thor
3
3
  # under Ruby's license.
4
4
  #
5
5
  class Options < Arguments #:nodoc:
6
- LONG_RE = /^(--\w+[-\w+]*)$/
6
+ LONG_RE = /^(--\w+(?:-\w+)*)$/
7
7
  SHORT_RE = /^(-[a-z])$/i
8
- EQ_RE = /^(--\w+[-\w+]*|-[a-z])=(.*)$/i
8
+ EQ_RE = /^(--\w+(?:-\w+)*|-[a-z])=(.*)$/i
9
9
  SHORT_SQ_RE = /^-([a-z]{2,})$/i # Allow either -x -v or -xv style for single char args
10
10
  SHORT_NUM = /^(-[a-z])#{NUMERIC}$/i
11
11
 
12
12
  # Receives a hash and makes it switches.
13
- #
14
13
  def self.to_switches(options)
15
14
  options.map do |key, value|
16
15
  case value
@@ -28,12 +27,18 @@ class Thor
28
27
  end.join(" ")
29
28
  end
30
29
 
31
- # Takes a hash of Thor::Option objects.
32
- #
33
- def initialize(options={})
34
- options = options.values
30
+ # Takes a hash of Thor::Option and a hash with defaults.
31
+ def initialize(hash_options={}, defaults={})
32
+ options = hash_options.values
35
33
  super(options)
36
- @shorts, @switches = {}, {}
34
+
35
+ # Add defaults
36
+ defaults.each do |key, value|
37
+ @assigns[key.to_s] = value
38
+ @non_assigned_required.delete(hash_options[key])
39
+ end
40
+
41
+ @shorts, @switches, @unknown = {}, {}, []
37
42
 
38
43
  options.each do |option|
39
44
  @switches[option.switch_name] = option
@@ -61,16 +66,24 @@ class Thor
61
66
  end
62
67
 
63
68
  switch = normalize_switch(switch)
64
- next unless option = switch_option(switch)
65
-
69
+ option = switch_option(switch)
66
70
  @assigns[option.human_name] = parse_peek(switch, option)
71
+ elsif current_is_switch_formatted?
72
+ @unknown << shift
67
73
  else
68
74
  shift
69
75
  end
70
76
  end
71
77
 
72
78
  check_requirement!
73
- @assigns
79
+
80
+ assigns = Thor::CoreExt::HashWithIndifferentAccess.new(@assigns)
81
+ assigns.freeze
82
+ assigns
83
+ end
84
+
85
+ def check_unknown!
86
+ raise UnknownArgumentError, "Unknown switches '#{@unknown.join(', ')}'" unless @unknown.empty?
74
87
  end
75
88
 
76
89
  protected
@@ -86,6 +99,19 @@ class Thor
86
99
  end
87
100
  end
88
101
 
102
+ def switch_formatted?(arg)
103
+ case arg
104
+ when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM, SHORT_SQ_RE
105
+ true
106
+ else
107
+ false
108
+ end
109
+ end
110
+
111
+ def current_is_switch_formatted?
112
+ switch_formatted? peek
113
+ end
114
+
89
115
  def switch?(arg)
90
116
  switch_option(arg) || @shorts.key?(arg)
91
117
  end
@@ -122,15 +148,16 @@ class Thor
122
148
  # Parse the value at the peek analyzing if it requires an input or not.
123
149
  #
124
150
  def parse_peek(switch, option)
125
- unless current_is_value?
151
+ if current_is_switch_formatted? || last?
126
152
  if option.boolean?
127
153
  # No problem for boolean types
128
154
  elsif no_or_skip?(switch)
129
155
  return nil # User set value to nil
130
156
  elsif option.string? && !option.required?
131
- return option.human_name # Return the option name
157
+ # Return the default if there is one, else the human name
158
+ return option.default || option.human_name
132
159
  else
133
- raise MalformattedArgumentError, "no value provided for option '#{switch}'"
160
+ raise MalformattedArgumentError, "No value provided for option '#{switch}'"
134
161
  end
135
162
  end
136
163
 
@@ -1,3 +1,7 @@
1
+ require 'thor'
2
+ require 'thor/group'
3
+ require 'thor/core_ext/file_binary_read'
4
+
1
5
  require 'fileutils'
2
6
  require 'open-uri'
3
7
  require 'yaml'
@@ -5,15 +9,14 @@ require 'digest/md5'
5
9
  require 'pathname'
6
10
 
7
11
  class Thor::Runner < Thor #:nodoc:
8
- map "-T" => :list, "-i" => :install, "-u" => :update
12
+ map "-T" => :list, "-i" => :install, "-u" => :update, "-v" => :version
9
13
 
10
14
  # Override Thor#help so it can give information about any class and any method.
11
15
  #
12
16
  def help(meth=nil)
13
17
  if meth && !self.respond_to?(meth)
14
18
  initialize_thorfiles(meth)
15
- klass, task = Thor::Util.namespace_to_thor_class_and_task(meth)
16
- # Send mapping -h because it works with Thor::Group too
19
+ klass, task = Thor::Util.find_class_and_task_by_namespace(meth)
17
20
  klass.start(["-h", task].compact, :shell => self.shell)
18
21
  else
19
22
  super
@@ -26,13 +29,13 @@ class Thor::Runner < Thor #:nodoc:
26
29
  def method_missing(meth, *args)
27
30
  meth = meth.to_s
28
31
  initialize_thorfiles(meth)
29
- klass, task = Thor::Util.namespace_to_thor_class_and_task(meth)
32
+ klass, task = Thor::Util.find_class_and_task_by_namespace(meth)
30
33
  args.unshift(task) if task
31
- klass.start(args, :shell => shell)
34
+ klass.start(args, :shell => self.shell)
32
35
  end
33
36
 
34
37
  desc "install NAME", "Install an optionally named Thor file into your system tasks"
35
- method_options :as => :string, :relative => :boolean
38
+ method_options :as => :string, :relative => :boolean, :force => :boolean
36
39
  def install(name)
37
40
  initialize_thorfiles
38
41
 
@@ -41,10 +44,10 @@ class Thor::Runner < Thor #:nodoc:
41
44
  begin
42
45
  if File.directory?(File.expand_path(name))
43
46
  base, package = File.join(name, "main.thor"), :directory
44
- contents = open(base).read
47
+ contents = open(base) {|input| input.read }
45
48
  else
46
49
  base, package = name, :file
47
- contents = open(name).read
50
+ contents = open(name) {|input| input.read }
48
51
  end
49
52
  rescue OpenURI::HTTPError
50
53
  raise Error, "Error opening URI '#{name}'"
@@ -55,7 +58,9 @@ class Thor::Runner < Thor #:nodoc:
55
58
  say "Your Thorfile contains:"
56
59
  say contents
57
60
 
58
- return false if no?("Do you wish to continue [y/N]?")
61
+ unless options["force"]
62
+ return false if no?("Do you wish to continue [y/N]?")
63
+ end
59
64
 
60
65
  as = options["as"] || begin
61
66
  first_line = contents.split("\n")[0]
@@ -93,6 +98,12 @@ class Thor::Runner < Thor #:nodoc:
93
98
  thor_yaml[as][:filename] # Indicate success
94
99
  end
95
100
 
101
+ desc "version", "Show Thor version"
102
+ def version
103
+ require 'thor/version'
104
+ say "Thor #{Thor::VERSION}"
105
+ end
106
+
96
107
  desc "uninstall NAME", "Uninstall a named Thor module"
97
108
  def uninstall(name)
98
109
  raise Error, "Can't find module '#{name}'" unless thor_yaml[name]
@@ -45,19 +45,16 @@ class Thor
45
45
 
46
46
  # Holds the shell for the given Thor instance. If no shell is given,
47
47
  # it gets a default shell from Thor::Base.shell.
48
- #
49
48
  def shell
50
49
  @shell ||= Thor::Base.shell.new
51
50
  end
52
51
 
53
52
  # Sets the shell for this thor class.
54
- #
55
53
  def shell=(shell)
56
54
  @shell = shell
57
55
  end
58
56
 
59
57
  # Common methods that are delegated to the shell.
60
- #
61
58
  SHELL_DELEGATED_METHODS.each do |method|
62
59
  module_eval <<-METHOD, __FILE__, __LINE__
63
60
  def #{method}(*args)
@@ -66,6 +63,14 @@ class Thor
66
63
  METHOD
67
64
  end
68
65
 
66
+ # Yields the given block with padding.
67
+ def with_padding
68
+ shell.padding += 1
69
+ yield
70
+ ensure
71
+ shell.padding -= 1
72
+ end
73
+
69
74
  protected
70
75
 
71
76
  # Allow shell to be shared between invocations.