pione 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/.gitignore +3 -2
  2. data/History.txt +6 -0
  3. data/Rakefile +1 -1
  4. data/bin/pione-broker +1 -1
  5. data/bin/pione-clean +1 -1
  6. data/bin/pione-client +1 -1
  7. data/bin/pione-log +1 -1
  8. data/bin/pione-relay +1 -1
  9. data/bin/pione-relay-account-db +1 -1
  10. data/bin/pione-relay-client-db +1 -1
  11. data/bin/pione-syntax-checker +1 -1
  12. data/bin/pione-task-worker +1 -1
  13. data/bin/pione-tuple-space-provider +1 -1
  14. data/bin/pione-tuple-space-receiver +1 -1
  15. data/bin/pione-tuple-space-viewer +1 -1
  16. data/bin/pione-val +1 -1
  17. data/example/CTFCorrection/CTFCorrection.pione +78 -0
  18. data/example/CTFCorrection/package.yml +1 -0
  19. data/example/HelloWorld/scenario/output/message.txt +1 -0
  20. data/example/LoopByTouch/LoopByTouch.pione +10 -18
  21. data/example/LoopByTouch/PairLoop.pione +18 -0
  22. data/example/LoopByTouch/SingleLoop.pione +5 -0
  23. data/example/LoopByTouch/TripletLoop.pione +24 -0
  24. data/example/MakePair/scenario/output/comb-1-2.pair +0 -0
  25. data/example/MakePair/scenario/output/comb-1-3.pair +0 -0
  26. data/example/MakePair/scenario/output/comb-1-4.pair +0 -0
  27. data/example/MakePair/scenario/output/comb-1-5.pair +0 -0
  28. data/example/MakePair/scenario/output/comb-2-3.pair +0 -0
  29. data/example/MakePair/scenario/output/comb-2-4.pair +0 -0
  30. data/example/MakePair/scenario/output/comb-2-5.pair +0 -0
  31. data/example/MakePair/scenario/output/comb-3-4.pair +0 -0
  32. data/example/MakePair/scenario/output/comb-3-5.pair +0 -0
  33. data/example/MakePair/scenario/output/comb-4-5.pair +0 -0
  34. data/example/MakePair/scenario/output/perm-1-2.pair +0 -0
  35. data/example/MakePair/scenario/output/perm-1-3.pair +0 -0
  36. data/example/MakePair/scenario/output/perm-1-4.pair +0 -0
  37. data/example/MakePair/scenario/output/perm-1-5.pair +0 -0
  38. data/example/MakePair/scenario/output/perm-2-1.pair +0 -0
  39. data/example/MakePair/scenario/output/perm-2-3.pair +0 -0
  40. data/example/MakePair/scenario/output/perm-2-4.pair +0 -0
  41. data/example/MakePair/scenario/output/perm-2-5.pair +0 -0
  42. data/example/MakePair/scenario/output/perm-3-1.pair +0 -0
  43. data/example/MakePair/scenario/output/perm-3-2.pair +0 -0
  44. data/example/MakePair/scenario/output/perm-3-4.pair +0 -0
  45. data/example/MakePair/scenario/output/perm-3-5.pair +0 -0
  46. data/example/MakePair/scenario/output/perm-4-1.pair +0 -0
  47. data/example/MakePair/scenario/output/perm-4-2.pair +0 -0
  48. data/example/MakePair/scenario/output/perm-4-3.pair +0 -0
  49. data/example/MakePair/scenario/output/perm-4-5.pair +0 -0
  50. data/example/MakePair/scenario/output/perm-5-1.pair +0 -0
  51. data/example/MakePair/scenario/output/perm-5-2.pair +0 -0
  52. data/example/MakePair/scenario/output/perm-5-3.pair +0 -0
  53. data/example/MakePair/scenario/output/perm-5-4.pair +0 -0
  54. data/example/MakePair/scenario/output/succ-1-2.pair +0 -0
  55. data/example/MakePair/scenario/output/succ-2-3.pair +0 -0
  56. data/example/MakePair/scenario/output/succ-3-4.pair +0 -0
  57. data/example/MakePair/scenario/output/succ-4-5.pair +0 -0
  58. data/example/SyntaxError/output_line_error.pione +6 -0
  59. data/example/WorkflowPatterns/38_GeneralSynchronizingMerge/GeneralSynchronizingMerge.pione +94 -0
  60. data/lib/pione.rb +1 -10
  61. data/lib/pione/agent/process-manager.rb +6 -5
  62. data/lib/pione/agent/rule-provider.rb +7 -9
  63. data/lib/pione/agent/task-worker.rb +1 -1
  64. data/lib/pione/command.rb +1 -0
  65. data/lib/pione/command/basic-command.rb +12 -77
  66. data/lib/pione/command/child-process.rb +19 -13
  67. data/lib/pione/command/daemon-process.rb +0 -9
  68. data/lib/pione/command/front-owner-command.rb +0 -6
  69. data/lib/pione/command/option.rb +243 -0
  70. data/lib/pione/command/pione-broker.rb +10 -5
  71. data/lib/pione/command/pione-clean.rb +4 -0
  72. data/lib/pione/command/pione-client.rb +257 -210
  73. data/lib/pione/command/pione-log.rb +38 -19
  74. data/lib/pione/command/pione-relay-account-db.rb +42 -17
  75. data/lib/pione/command/pione-relay-client-db.rb +35 -14
  76. data/lib/pione/command/pione-relay.rb +16 -8
  77. data/lib/pione/command/pione-syntax-checker.rb +33 -13
  78. data/lib/pione/command/pione-task-worker.rb +26 -23
  79. data/lib/pione/command/pione-tuple-space-provider.rb +8 -17
  80. data/lib/pione/command/pione-tuple-space-receiver.rb +13 -3
  81. data/lib/pione/command/pione-tuple-space-viewer.rb +42 -23
  82. data/lib/pione/command/pione-val.rb +15 -7
  83. data/lib/pione/component/document.rb +49 -70
  84. data/lib/pione/component/package.rb +125 -83
  85. data/lib/pione/location/basic-location.rb +1 -0
  86. data/lib/pione/model/assignment.rb +11 -0
  87. data/lib/pione/model/parameters.rb +10 -0
  88. data/lib/pione/model/variable.rb +14 -0
  89. data/lib/pione/parser/common-parser.rb +4 -0
  90. data/lib/pione/parser/document-parser.rb +4 -3
  91. data/lib/pione/parser/rule-definition-parser.rb +2 -1
  92. data/lib/pione/patch/rinda-patch.rb +1 -1
  93. data/lib/pione/rule-handler/action-handler.rb +6 -1
  94. data/lib/pione/rule-handler/basic-handler.rb +0 -6
  95. data/lib/pione/rule-handler/flow-handler.rb +14 -9
  96. data/lib/pione/system/global.rb +3 -0
  97. data/lib/pione/system/package-cache.rb +18 -0
  98. data/lib/pione/transformer/document-transformer.rb +26 -3
  99. data/lib/pione/transformer/rule-definition-transformer.rb +10 -2
  100. data/lib/pione/tuple-space/presence-notifier.rb +4 -3
  101. data/lib/pione/uri-scheme.rb +11 -0
  102. data/lib/pione/uri-scheme/git-scheme.rb +12 -0
  103. data/lib/pione/util.rb +2 -0
  104. data/lib/pione/util/package-parameters-list.rb +32 -0
  105. data/lib/pione/util/process-info.rb +21 -0
  106. data/lib/pione/version.rb +1 -1
  107. data/pione.gemspec +1 -1
  108. data/test/agent/spec_rule-provider.rb +57 -44
  109. data/test/command/command-behavior.rb +15 -0
  110. data/test/command/spec_pione-client.rb +56 -0
  111. data/test/command/spec_pione-val.domain.dump +0 -0
  112. data/test/command/spec_pione-val.rb +22 -0
  113. data/test/component/spec_document.pione +51 -0
  114. data/test/component/spec_document.rb +41 -70
  115. data/test/component/spec_package.rb +18 -3
  116. data/test/parser/spec_document-parser.yml +15 -0
  117. data/test/parser/spec_rule-definition-parser.yml +7 -2
  118. data/test/rule-handler/spec_action-handler.rb +6 -6
  119. data/test/rule-handler/spec_flow-handler.pione +25 -0
  120. data/test/rule-handler/spec_flow-handler.rb +35 -95
  121. data/test/rule-handler/spec_update-criteria.rb +2 -2
  122. data/test/test-util.rb +68 -4
  123. data/test/transformer/spec_block-transformer.rb +1 -1
  124. data/test/transformer/spec_document-transformer.rb +50 -0
  125. data/test/transformer/spec_expr-transformer.rb +1 -1
  126. data/test/transformer/spec_flow-element-transformer.rb +13 -13
  127. data/test/transformer/spec_literal-transformer.rb +1 -1
  128. data/test/transformer/spec_rule-definition-transformer.rb +31 -19
  129. data/test/uri-scheme/spec_git-scheme.rb +20 -0
  130. data/test/util/spec_id.rb +6 -6
  131. data/test/util/spec_package-parameters-list.rb +59 -0
  132. data/test/util/spec_package-parameters-list_1.pione +17 -0
  133. data/test/util/spec_package-parameters-list_2.pione +13 -0
  134. data/test/util/spec_package-parameters-list_3.pione +12 -0
  135. data/test/util/spec_package-parameters-list_4.pione +6 -0
  136. data/test/util/spec_process-info.rb +56 -0
  137. metadata +79 -16
  138. data/lib/pione/option.rb +0 -13
  139. data/lib/pione/option/child-process-option.rb +0 -19
  140. data/lib/pione/option/common-option.rb +0 -31
  141. data/lib/pione/option/option-interface.rb +0 -73
  142. data/lib/pione/option/presence-notifier-option.rb +0 -16
  143. data/lib/pione/option/task-worker-owner-option.rb +0 -24
  144. data/lib/pione/option/tuple-space-provider-option.rb +0 -28
  145. data/lib/pione/option/tuple-space-provider-owner-option.rb +0 -18
  146. data/lib/pione/option/tuple-space-receiver-option.rb +0 -8
data/lib/pione.rb CHANGED
@@ -58,13 +58,7 @@ require 'pione/patch/rinda-patch'
58
58
  require 'pione/patch/uri-patch'
59
59
  require 'pione/patch/monitor-patch'
60
60
 
61
- # uri-scheme
62
- require 'pione/uri-scheme/basic-scheme'
63
- require 'pione/uri-scheme/local-scheme'
64
- require 'pione/uri-scheme/dropbox-scheme'
65
- require 'pione/uri-scheme/broadcast-scheme'
66
- require 'pione/uri-scheme/myftp-scheme'
67
-
61
+ require 'pione/uri-scheme'
68
62
  require 'pione/location'
69
63
  require 'pione/log'
70
64
  require 'pione/system'
@@ -136,9 +130,6 @@ require 'pione/front/tuple-space-provider-front'
136
130
  require 'pione/front/tuple-space-receiver-front'
137
131
  require 'pione/front/relay-front'
138
132
 
139
- # command-option
140
- require 'pione/option'
141
-
142
133
  # command
143
134
  require 'pione/command'
144
135
 
@@ -8,12 +8,12 @@ module Pione
8
8
  define_state_transition :sleeping => :running
9
9
  define_state_transition :running => :sleeping
10
10
 
11
- attr_reader :document
11
+ attr_reader :package
12
12
 
13
- def initialize(tuple_space_server, document, params, stream)
14
- raise ArgumentError unless document.main
13
+ def initialize(tuple_space_server, package, params, stream)
14
+ raise ArgumentError unless package.find_rule("Main")
15
15
  super(tuple_space_server)
16
- @document = document
16
+ @package = package
17
17
  @params = params
18
18
  @stream = stream
19
19
  end
@@ -23,7 +23,8 @@ module Pione
23
23
  end
24
24
 
25
25
  def transit_to_running
26
- if handler = @document.root_rule(@params).make_handler(tuple_space_server)
26
+ root = @package.create_root_rule(@package.find_rule("Main"), @params)
27
+ if handler = root.make_handler(tuple_space_server)
27
28
  handler.handle
28
29
  else
29
30
  user_message "error: no inputs"
@@ -14,15 +14,13 @@ module Pione
14
14
  end
15
15
  end
16
16
 
17
- def read_document(doc)
18
- doc.rules.each do |rule_path, rule|
19
- add_rule(rule_path, rule)
20
- end
21
- end
22
-
23
- def add_rule(rule_path, content)
24
- raise ArgumentError unless content.kind_of?(Component::Rule)
25
- @table[rule_path] = content
17
+ # Read rules from the document or the package.
18
+ #
19
+ # @param document [Component::Document,Component::Package]
20
+ # document or package
21
+ # @return [void]
22
+ def read_rules(document)
23
+ document.rules.each {|rule| @table[rule.path] = rule}
26
24
  end
27
25
 
28
26
  # Return known rule pathes.
@@ -52,7 +52,7 @@ module Pione
52
52
  unless thread.alive?
53
53
  Process.abort("You cannot run pione-task-worker.")
54
54
  end
55
- return thread
55
+ return Util::ProcessInfo.new(pid, thread)
56
56
  end
57
57
 
58
58
  define_state :task_waiting
data/lib/pione/command.rb CHANGED
@@ -3,6 +3,7 @@ module Pione
3
3
  module Command; end
4
4
  end
5
5
 
6
+ require 'pione/command/option'
6
7
  require 'pione/command/basic-command'
7
8
  require 'pione/command/front-owner-command'
8
9
  require 'pione/command/daemon-process'
@@ -48,63 +48,10 @@ module Pione
48
48
  end
49
49
  end
50
50
 
51
- # CommandOption is a class for holding option data set.
52
- class CommandOption < PioneObject
53
- def_delegators :@data, :[], :[]=
54
-
55
- # Creata a command option context.
56
- #
57
- # @param command_info [CommandInfo]
58
- # command informations
59
- def initialize(command_info)
60
- extend Option::OptionInterface
61
- @command_info = command_info
62
- @data = {}
63
- end
64
-
65
- # Parse the command options.
66
- #
67
- # @return [void]
68
- def parse
69
- OptionParser.new do |opt|
70
- # set banner
71
- opt.banner = "Usage: %s [options]" % opt.program_name
72
- opt.banner << "\n" + @command_info.banner if @command_info.banner
73
-
74
- # set version
75
- opt.version = Pione::VERSION
76
-
77
- # set default values
78
- default_table.each do |key, value|
79
- @data[key] = value
80
- end
81
-
82
- # set options
83
- definitions.sort{|a,b| a.first <=> b.first}.each do |args, b|
84
- opt.on(*args, Proc.new{|*args| self.instance_exec(@data, *args, &b)})
85
- end
86
- end.parse!(ARGV)
87
- rescue OptionParser::InvalidOption => e
88
- e.args.each {|arg| $stderr.puts "Unknown option: %s" % arg }
89
- abort
90
- rescue OptionParser::MissingArgument => e
91
- abort(e.message)
92
- end
93
-
94
- # Check validness of the command options.
95
- #
96
- # @return [void]
97
- def check
98
- validators.each do |validator|
99
- validator.call(@data)
100
- end
101
- end
102
- end
103
-
104
51
  # BasicCommand is a base class for PIONE commands.
105
52
  class BasicCommand < PioneObject
106
53
  @info = CommandInfo.new
107
- @option = CommandOption.new(@info).tap {|x| x.use Option::CommonOption}
54
+ @option = Option.new(@info.name, @info.banner)
108
55
  @pre_preparations = []
109
56
  @preparations = []
110
57
  @post_preparations = []
@@ -133,7 +80,7 @@ module Pione
133
80
  parent_option = self.option
134
81
  subclass.instance_eval do
135
82
  @info = CommandInfo.new
136
- @option = CommandOption.new(@info).tap {|x| x.use parent_option}
83
+ @option = Option.new(@info.name, @info.banner)
137
84
  end
138
85
  setter = lambda{|name, data| subclass.instance_variable_set(name, data.clone)}
139
86
  setter.call(:@pre_preparations, self.pre_preparations)
@@ -232,25 +179,15 @@ module Pione
232
179
  # Run the command.
233
180
  #
234
181
  # @return [void]
235
- def run(*args)
236
- self.new(*args).run
182
+ def run(argv)
183
+ self.new(argv).run
237
184
  end
238
185
  end
239
186
 
240
- # Return a command option.
241
- #
242
- # @return [CommandOption]
243
- # command option
244
- def option
245
- self.class.option
246
- end
187
+ forward! :class, :option, :info
247
188
 
248
- # Return a command info.
249
- #
250
- # @return [CommandInfo]
251
- # command info
252
- def info
253
- self.class.info
189
+ def initialize(argv)
190
+ @argv = argv
254
191
  end
255
192
 
256
193
  # Run the command.
@@ -273,11 +210,7 @@ module Pione
273
210
  caller = lambda do |name|
274
211
  self.class.__send__(name).reverse.each do |proc|
275
212
  puts "%s(%s):%s:%s" % [info.name, name, *proc.source_location] if Pione.debug_mode?
276
- begin
277
- receiver.instance_eval(&proc)
278
- rescue Object => e
279
- Util::ErrorReport.print e
280
- end
213
+ receiver.instance_eval(&proc)
281
214
  end
282
215
  end
283
216
  caller.call(:pre_terminations)
@@ -295,8 +228,10 @@ module Pione
295
228
  end
296
229
  end
297
230
 
231
+ Signal.trap(:TERM) { call_terminations }
232
+
298
233
  # parse options
299
- option.parse
234
+ option.parse(@argv)
300
235
  end
301
236
 
302
237
  prepare do
@@ -312,7 +247,7 @@ module Pione
312
247
  terminate(:post) do
313
248
  Global.monitor.synchronize do
314
249
  # exit with no exception
315
- exit!
250
+ exit Global.exit_status
316
251
  end
317
252
  end
318
253
  end
@@ -4,23 +4,29 @@ module Pione
4
4
  # processes.
5
5
  class ChildProcess < FrontOwnerCommand
6
6
  define_option do
7
- default :no_parent_front, false
8
-
9
- # --parent-front
10
- option('--parent-front=URI', 'set parent front URI') do |data, uri|
11
- data[:parent_front] = DRbObject.new_with_uri(uri)
12
- end
13
-
14
- # --no-parent
15
- option('--no-parent', 'turn on no parent mode') do |data|
16
- data[:no_parent_mode] = true
7
+ define(:parent_front) do |item|
8
+ item.long = '--parent-front=URI'
9
+ item.desc = 'set parent front URI'
10
+ item.default = false
11
+ item.action = proc do |option, uri|
12
+ option[:parent_front] = DRbObject.new_with_uri(uri)
13
+ end
17
14
  end
18
15
 
19
- validate do |data|
20
- if not(data[:no_parent_mode]) and data[:parent_front].nil?
21
- abort("option error: no caller front address")
16
+ define(:no_parent) do |item|
17
+ item.long = '--no-parent'
18
+ item.desc = 'turn on no parent mode'
19
+ item.default = false
20
+ item.action = proc do |option|
21
+ option[:no_parent_mode] = true
22
22
  end
23
23
  end
24
+
25
+ # validate do |option|
26
+ # if not(option[:no_parent_mode]) and option[:parent_front].nil?
27
+ # abort("option error: no caller front address")
28
+ # end
29
+ # end
24
30
  end
25
31
 
26
32
  prepare do
@@ -2,15 +2,6 @@ module Pione
2
2
  module Command
3
3
  # DaemonProcess is a class for commands that enable to daemonize.
4
4
  class DaemonProcess < FrontOwnerCommand
5
- define_option do
6
- default :daemon, false
7
-
8
- # --daemon
9
- option("--daemon", "turn on daemon mode") do |data|
10
- data[:daemon] = true
11
- end
12
- end
13
-
14
5
  prepare(:post) do
15
6
  Process.daemon(true, true) if option[:daemon]
16
7
  end
@@ -2,12 +2,6 @@ module Pione
2
2
  module Command
3
3
  # FrontOwnerCommand is a parent of classes that own front server.
4
4
  class FrontOwnerCommand < BasicCommand
5
- define_option do
6
- option("--my-ip-address=ADDRESS", "set my IP address") do |data, address|
7
- Global.my_ip_address = address
8
- end
9
- end
10
-
11
5
  prepare do
12
6
  Global.front = create_front
13
7
  end
@@ -0,0 +1,243 @@
1
+ module Pione
2
+ module Command
3
+ # OptionItem is an option item for PIONE command.
4
+ class OptionItem < StructX
5
+ member :name
6
+ member :short
7
+ member :long
8
+ member :desc
9
+ member :default
10
+ member :value
11
+ member :values
12
+ member :action
13
+ member :validator
14
+ end
15
+
16
+ # OptionInterface provides basic methods for option modules. All option
17
+ # modules should be extended by this.
18
+ module OptionInterface
19
+ attr_reader :items
20
+
21
+ # Define a new option for the command.
22
+ #
23
+ # @param args [Array]
24
+ # OptionParser arguments
25
+ # @param b [Proc]
26
+ # option action
27
+ # @return [void]
28
+ def define(name, &b)
29
+ item = OptionItem.new.tap do |item|
30
+ item.name = name
31
+ b.call(item)
32
+ end
33
+
34
+ if self.kind_of?(Module)
35
+ singleton_class.send(:define_method, name) {item}
36
+ else
37
+ @items << item
38
+ end
39
+ end
40
+
41
+ # Install the option module.
42
+ #
43
+ # @param mod [Module]
44
+ # PIONE's option set modules
45
+ # @return [void]
46
+ def use(item_name)
47
+ @items << CommonOption.send(item_name)
48
+ end
49
+ end
50
+
51
+ # CommandOption is a class for holding option data set.
52
+ class Option
53
+ forward! :@option, :"[]", :"[]="
54
+
55
+ # Creata a command option context.
56
+ #
57
+ # @param command_info [CommandInfo]
58
+ # command informations
59
+ def initialize(program_name, banner)
60
+ extend OptionInterface
61
+ @program_name = program_name
62
+ @banner = banner
63
+ @option = {}
64
+ @items = []
65
+ @validators = []
66
+ end
67
+
68
+ def item(name)
69
+ @items.find {|item| item.name == name}
70
+ end
71
+
72
+ # Parse the command options.
73
+ #
74
+ # @return [void]
75
+ def parse(argv)
76
+ OptionParser.new do |opt|
77
+ # set banner
78
+ opt.banner = "Usage: %s [options]" % @program_name
79
+ opt.banner << "\n" + @banner if @banner
80
+
81
+ # set version
82
+ opt.program_name = @program_name
83
+ opt.version = Pione::VERSION
84
+
85
+ # default values
86
+ @items.each {|item| @option[item.name] = item.default if item.default}
87
+
88
+ # setup option parser
89
+ @items.sort{|a,b| a.long <=> b.long}.each {|item| setup_item(opt, item)}
90
+ end.parse!(argv)
91
+ rescue OptionParser::InvalidOption => e
92
+ e.args.each {|arg| $stderr.puts "Unknown option: %s" % arg }
93
+ abort
94
+ rescue OptionParser::MissingArgument => e
95
+ abort(e.message)
96
+ end
97
+
98
+ def default(name, value)
99
+ @option[name] = value
100
+ end
101
+
102
+ def validate(&b)
103
+ @validators << b
104
+ end
105
+
106
+ # Check validness of the command options.
107
+ #
108
+ # @return [void]
109
+ def check
110
+ @validators.each do |validator|
111
+ validator.call(@option)
112
+ end
113
+ end
114
+
115
+ private
116
+
117
+ SETUP_ITEM_LIST = [
118
+ :setup_item_action,
119
+ :setup_item_values,
120
+ :setup_item_value,
121
+ :setup_item_static_value
122
+ ]
123
+
124
+ # Setup the option item.
125
+ def setup_item(opt, item)
126
+ defs = [item.short, item.long, item.desc].compact
127
+ SETUP_ITEM_LIST.find {|name| send(name, opt, item, defs)}
128
+ end
129
+
130
+ def setup_item_action(opt, item, defs)
131
+ if item.action
132
+ opt.on(*defs, Proc.new{|*args| self.instance_exec(@option, *args, &item.action)})
133
+ end
134
+ end
135
+
136
+ def setup_item_values(opt, item, defs)
137
+ if item.values.kind_of?(Proc)
138
+ opt.on(*defs, Proc.new{|*args| @option[item.name] << self.instance_exec(*args, &item.values)})
139
+ end
140
+ end
141
+
142
+ def setup_item_value(opt, item, defs)
143
+ if item.value.kind_of?(Proc)
144
+ opt.on(*defs, Proc.new{|*args| @option[item.name] = self.instance_exec(*args, &item.value)})
145
+ end
146
+ end
147
+
148
+ def setup_item_static_value(opt, item, defs)
149
+ if item.value
150
+ opt.on(*defs, Proc.new{ @option[item.name] = item.value})
151
+ end
152
+ end
153
+ end
154
+
155
+ # CommonOption provides common options for pione commands.
156
+ module CommonOption
157
+ extend OptionInterface
158
+
159
+ define(:color) do |item|
160
+ item.long = '--[no-]color'
161
+ item.desc = 'turn on/off color mode'
162
+ item.action = proc {|_, bool| Sickill::Rainbow.enabled = bool}
163
+ end
164
+
165
+ define(:daemon) do |item|
166
+ item.long = "--daemon"
167
+ item.desc = "turn on daemon mode"
168
+ item.default = false
169
+ item.value = true
170
+ end
171
+
172
+ define(:debug) do |item|
173
+ item.long = '--debug'
174
+ item.desc = "turn on debug mode"
175
+ item.action = proc {Pione.debug_mode = true}
176
+ end
177
+
178
+ define(:features) do |item|
179
+ item.long = '--features=FEATURES'
180
+ item.desc = 'set features'
181
+ item.value = proc {|features| features}
182
+ end
183
+
184
+ define(:my_ip_address) do |item|
185
+ item.long = "--my-ip-address=ADDRESS"
186
+ item.desc = "set my IP address"
187
+ item.action = proc {|_, address| Global.my_ip_address = address}
188
+ end
189
+
190
+ define(:no_parent) do |item|
191
+ item.long = '--no-parent'
192
+ item.desc = 'turn on no parent mode'
193
+ item.action = proc {|option| option[:no_parent_mode] = true}
194
+ end
195
+
196
+ define(:parent_front) do |item|
197
+ item.long = '--parent-front=URI'
198
+ item.desc = 'set parent front URI'
199
+ item.action = proc do |option, uri|
200
+ option[:parent_front] = DRbObject.new_with_uri(uri)
201
+ end
202
+ end
203
+
204
+ define(:presence_notification_address) do |item|
205
+ item.long = "--presence-notification-address=255.255.255.255:%s" % Global.presence_port
206
+ item.desc = "set the address for sending presence notifier"
207
+ item.action = proc do |_, address|
208
+ # clear addresses at first time
209
+ unless @__option_notifier_address__
210
+ @__option_notifier_address__ = true
211
+ Global.presence_notification_addresses = []
212
+ end
213
+ # add the address
214
+ address = address =~ /^broadcast/ ? address : "broadcast://%s" % address
215
+ uri = URI.parse(address)
216
+ uri.host = "255.255.255.255" if uri.host.nil?
217
+ uri.port = Global.presence_port if uri.port.nil?
218
+ Global.presence_notification_addresses << uri
219
+ end
220
+ end
221
+
222
+ define(:show_communication) do |item|
223
+ item.long = '--show-communication'
224
+ item.desc = "show object communication"
225
+ item.action = proc {Global.show_communication = true}
226
+ end
227
+
228
+ define(:show_presence_notifier) do |item|
229
+ item.long = "--show-presence-notifier"
230
+ item.desc = "show presence notifier informations"
231
+ item.action = proc {Global.show_presence_notifier = true}
232
+ end
233
+
234
+ define(:task_worker) do |item|
235
+ item.short = '-t N'
236
+ item.long = '--task-worker=N'
237
+ item.desc = 'set task worker number that this process creates'
238
+ item.default = Agent::TaskWorker.default_number
239
+ item.value = proc {|n| n.to_i}
240
+ end
241
+ end
242
+ end
243
+ end