tla-sbuilder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +328 -0
  3. data/VERSION +1 -0
  4. data/bin/sbuilder.rb +5 -0
  5. data/lib/cli/cli-customer.rb +420 -0
  6. data/lib/cli/cli-example.rb +92 -0
  7. data/lib/cli/cli-pet.rb +767 -0
  8. data/lib/cli/cli-text.rb +226 -0
  9. data/lib/cli/cli.rb +298 -0
  10. data/lib/sbuilder.rb +52 -0
  11. data/lib/sbuilder/constants.rb +72 -0
  12. data/lib/sbuilder/controller.rb +798 -0
  13. data/lib/sbuilder/default-sbuilder.yaml +372 -0
  14. data/lib/sbuilder/domain.rb +124 -0
  15. data/lib/sbuilder/domain_cardinality.rb +37 -0
  16. data/lib/sbuilder/domain_value.rb +81 -0
  17. data/lib/sbuilder/exception.rb +27 -0
  18. data/lib/sbuilder/extension_loader.rb +721 -0
  19. data/lib/sbuilder/factory.rb +234 -0
  20. data/lib/sbuilder/model.rb +356 -0
  21. data/lib/sbuilder/mustache/template.rb +125 -0
  22. data/lib/sbuilder/mustache/template_reader.rb +206 -0
  23. data/lib/sbuilder/mustache/template_reader_context.rb +371 -0
  24. data/lib/sbuilder/param_set.rb +132 -0
  25. data/lib/sbuilder/param_set_db.rb +20 -0
  26. data/lib/sbuilder/param_set_def.rb +57 -0
  27. data/lib/sbuilder/param_set_if.rb +68 -0
  28. data/lib/sbuilder/param_set_loader.rb +77 -0
  29. data/lib/sbuilder/param_set_loader_swagger.rb +424 -0
  30. data/lib/sbuilder/param_set_step.rb +62 -0
  31. data/lib/sbuilder/param_sets.rb +54 -0
  32. data/lib/sbuilder/parameter.rb +97 -0
  33. data/lib/sbuilder/parameter_container.rb +72 -0
  34. data/lib/sbuilder/parameter_dom.rb +70 -0
  35. data/lib/sbuilder/parameter_ref.rb +71 -0
  36. data/lib/sbuilder/resolver.rb +78 -0
  37. data/lib/sbuilder/resolver_loader.rb +79 -0
  38. data/lib/sbuilder/resolver_loader_yaml.rb +103 -0
  39. data/lib/sbuilder/resolver_rule.rb +36 -0
  40. data/lib/sbuilder/resolver_rule_match.rb +55 -0
  41. data/lib/sbuilder/resolver_rule_ref.rb +37 -0
  42. data/lib/utils/hash_inject.rb +12 -0
  43. data/lib/utils/logger.rb +80 -0
  44. data/lib/utils/netio.rb +58 -0
  45. data/lib/utils/string_inject.rb +10 -0
  46. data/lib/utils/version.rb +13 -0
  47. data/mustache/cfg/const_def.mustache +8 -0
  48. data/mustache/cfg/const_run.mustache +3 -0
  49. data/mustache/cfg/invariant-infrastructure-service.mustache +4 -0
  50. data/mustache/cfg/macro_run.mustache +6 -0
  51. data/mustache/cfg/module_footer.mustache +0 -0
  52. data/mustache/cfg/module_header.mustache +7 -0
  53. data/mustache/data-model-dump.mustache +19 -0
  54. data/mustache/data-model-footer.mustache +5 -0
  55. data/mustache/data-model-header.mustache +16 -0
  56. data/mustache/definition_types.mustache +40 -0
  57. data/mustache/domains.mustache +20 -0
  58. data/mustache/domains_assign.mustache +22 -0
  59. data/mustache/domains_run.mustache +21 -0
  60. data/mustache/extend/extend_assumptions.mustache +7 -0
  61. data/mustache/extend/extend_const.mustache +5 -0
  62. data/mustache/extend/extend_implementation.mustache +9 -0
  63. data/mustache/extend/extend_invariant.mustache +7 -0
  64. data/mustache/extend/extend_invariant_cfg.mustache +7 -0
  65. data/mustache/extend/extend_macros.mustache +19 -0
  66. data/mustache/extend/extend_operations.mustache +9 -0
  67. data/mustache/extend/extend_state.mustache +9 -0
  68. data/mustache/infrastructure-service-init.mustache +36 -0
  69. data/mustache/infrastructure-service-variables.mustache +10 -0
  70. data/mustache/interface_processes.mustache +38 -0
  71. data/mustache/interface_stubs_dummy.mustache +13 -0
  72. data/mustache/interface_types.mustache +52 -0
  73. data/mustache/markdown-header.mustache +24 -0
  74. data/mustache/markdown-toc.mustache +13 -0
  75. data/mustache/name_definition_type.mustache +5 -0
  76. data/mustache/name_domain.mustache +5 -0
  77. data/mustache/name_domain_value.mustache +5 -0
  78. data/mustache/name_domain_value_prefix.mustache +5 -0
  79. data/mustache/name_interface_response_type.mustache +6 -0
  80. data/mustache/name_interface_type.mustache +6 -0
  81. data/mustache/name_parameter_definition.mustache +5 -0
  82. data/mustache/name_parameter_type.mustache +6 -0
  83. data/mustache/name_process.mustache +6 -0
  84. data/mustache/name_type_invariant.mustache +5 -0
  85. data/mustache/name_variable.mustache +6 -0
  86. data/mustache/operator-infrastructure-service.mustache +13 -0
  87. data/mustache/possibility/module_extends.mustache +1 -0
  88. data/mustache/possibility/module_footer.mustache +1 -0
  89. data/mustache/possibility/module_header.mustache +8 -0
  90. data/mustache/possibility/possibility_definition.mustache +12 -0
  91. data/mustache/possibility/possibility_directive.mustache +1 -0
  92. data/mustache/possibility/possility_setup.mustache +28 -0
  93. data/mustache/setup/module_footer.mustache +1 -0
  94. data/mustache/setup/module_header.mustache +9 -0
  95. data/mustache/setup/operator_run.mustache +7 -0
  96. data/mustache/setup/operator_tick.mustache +2 -0
  97. data/mustache/setup/steps_run.mustache +22 -0
  98. data/mustache/setup/steps_run_bind_rule.mustache +51 -0
  99. data/mustache/setup/steps_run_bind_set.mustache +37 -0
  100. data/mustache/setup/steps_run_parameterBind.mustache +80 -0
  101. data/mustache/setup/steps_run_parameterExact.mustache +79 -0
  102. data/mustache/state_type_invariant-infrastructure-service.mustache +49 -0
  103. data/mustache/state_type_invariant.mustache +17 -0
  104. data/mustache/state_type_invariant_cfg.mustache +18 -0
  105. data/mustache/state_variables.mustache +20 -0
  106. data/mustache/tla/const_def.mustache +5 -0
  107. data/mustache/tla/const_run.mustache +3 -0
  108. data/mustache/tla/macro-infrastructure-service.mustache +14 -0
  109. data/mustache/tla/macro_run.mustache +40 -0
  110. data/mustache/tla/module_footer.mustache +2 -0
  111. data/mustache/tla/module_header.mustache +9 -0
  112. data/mustache/tla/operator_run.mustache +8 -0
  113. data/mustache/tla/operators-infrastructure-service.mustache +12 -0
  114. data/mustache/tla/plc_define_footer.mustache +1 -0
  115. data/mustache/tla/plc_define_header.mustache +1 -0
  116. data/mustache/tla/plc_define_run.mustache +59 -0
  117. data/mustache/tla/plc_footer.mustache +2 -0
  118. data/mustache/tla/plc_header.mustache +2 -0
  119. data/mustache/tla/plc_run_state.mustache +12 -0
  120. data/mustache/tla/plc_tail.mustache +8 -0
  121. data/mustache/tla/plc_translation.mustache +2 -0
  122. data/resources/schema/json_schema/draft-04.json +150 -0
  123. data/resources/schema/swagger/2.0/schema.json +1591 -0
  124. data/src-extend/README +2 -0
  125. data/src-extend/extend/extend_assumptions.mustache +7 -0
  126. data/src-extend/extend/extend_const.mustache +5 -0
  127. data/src-extend/extend/extend_implementation.mustache +9 -0
  128. data/src-extend/extend/extend_invariant.mustache +11 -0
  129. data/src-extend/extend/extend_invariant_cfg.mustache +7 -0
  130. data/src-extend/extend/extend_macros.mustache +19 -0
  131. data/src-extend/extend/extend_operations.mustache +9 -0
  132. data/src-extend/extend/extend_state.mustache +9 -0
  133. data/src-extend/extend_app/assumption +20 -0
  134. data/src-extend/extend_app/correctness +19 -0
  135. data/src-extend/extend_app/correctness.cfg +9 -0
  136. data/src-extend/extend_app/infrastructure +25 -0
  137. data/src-extend/extend_app/interface +11 -0
  138. data/src-extend/extend_app/operator +18 -0
  139. data/src-extend/extend_app/possibility +16 -0
  140. data/src-extend/extend_app/service +33 -0
  141. data/src-extend/extend_app/state +16 -0
  142. data/src-extend/extend_app/transaction +22 -0
  143. data/src/pet/assumption +29 -0
  144. data/src/pet/assumption_address_domains.tla +12 -0
  145. data/src/pet/assumption_domains.tla +16 -0
  146. data/src/pet/assumption_generic.tla +8 -0
  147. data/src/pet/assumption_id_domains.tla +2 -0
  148. data/src/pet/assumption_owner_domains.tla +14 -0
  149. data/src/pet/assumption_pet_domains.tla +16 -0
  150. data/src/pet/assumption_tag_domains.tla +13 -0
  151. data/src/pet/correctness +24 -0
  152. data/src/pet/correctness.cfg +9 -0
  153. data/src/pet/correctness_coherent_owner_address.tla +6 -0
  154. data/src/pet/correctness_pet_name.tla +4 -0
  155. data/src/pet/correctness_ref_tag.tla +13 -0
  156. data/src/pet/correctness_type_invariants.tla +12 -0
  157. data/src/pet/correctness_unique_pet.tla +3 -0
  158. data/src/pet/correctness_unique_tag.tla +3 -0
  159. data/src/pet/docs/Petstore.md +117 -0
  160. data/src/pet/extend/extend_assumptions.mustache +7 -0
  161. data/src/pet/extend/extend_implementation.mustache +9 -0
  162. data/src/pet/extend/extend_invariant.mustache +11 -0
  163. data/src/pet/extend/extend_invariant_cfg.mustache +7 -0
  164. data/src/pet/extend/extend_macros.mustache +19 -0
  165. data/src/pet/extend/extend_operations.mustache +9 -0
  166. data/src/pet/extend/extend_state.mustache +9 -0
  167. data/src/pet/infrastructure +25 -0
  168. data/src/pet/infrastructure_id_get.tla +24 -0
  169. data/src/pet/interface +12 -0
  170. data/src/pet/interface_delete_pet.tla +5 -0
  171. data/src/pet/interface_get_pet.tla +4 -0
  172. data/src/pet/interface_post_pet.tla +5 -0
  173. data/src/pet/interface_post_tag.tla +5 -0
  174. data/src/pet/interface_put_tag.tla +3 -0
  175. data/src/pet/operator +30 -0
  176. data/src/pet/operator_find_tag_by_owner_name.tla +1 -0
  177. data/src/pet/operator_get_pet.tla +4 -0
  178. data/src/pet/operator_get_pet_by_tag.tla +4 -0
  179. data/src/pet/operator_get_tag.tla +10 -0
  180. data/src/pet/operator_new_owner.tla +3 -0
  181. data/src/pet/operator_new_pet.tla +13 -0
  182. data/src/pet/operator_new_tag.tla +3 -0
  183. data/src/pet/operator_next_pet_id.tla +3 -0
  184. data/src/pet/operator_responses.tla +8 -0
  185. data/src/pet/operator_tag_exists.tla +2 -0
  186. data/src/pet/operator_tag_owner_validated.tla +2 -0
  187. data/src/pet/operator_tag_referenced.tla +4 -0
  188. data/src/pet/operator_valid_owner.tla +17 -0
  189. data/src/pet/operator_valid_pet.tla +6 -0
  190. data/src/pet/operator_valid_tag.tla +5 -0
  191. data/src/pet/possibility +18 -0
  192. data/src/pet/possibility_at_least_two_tags.tla +12 -0
  193. data/src/pet/possibility_invalid_tag_address.tla +8 -0
  194. data/src/pet/service +35 -0
  195. data/src/pet/service_pet_delete.tla +11 -0
  196. data/src/pet/service_pet_get.tla +27 -0
  197. data/src/pet/service_pet_post.tla +78 -0
  198. data/src/pet/service_tag_post.tla +53 -0
  199. data/src/pet/service_tag_put.tla +82 -0
  200. data/src/pet/state +16 -0
  201. data/src/pet/state_infra.tla +6 -0
  202. data/src/pet/state_pet.tla +5 -0
  203. data/src/pet/state_tag_id.tla +2 -0
  204. data/src/pet/transaction +23 -0
  205. data/src/pet/transaction_delete_pet.tla +13 -0
  206. data/src/pet/transaction_enter_pet.tla +13 -0
  207. data/src/pet/transaction_enter_tag.tla +56 -0
  208. data/src/pet/transaction_error.tla +23 -0
  209. data/tla-sbuilder.gemspec +43 -0
  210. metadata +353 -0
@@ -0,0 +1,226 @@
1
+ module Sbuilder
2
+
3
+ class CliText
4
+
5
+ SBUILDER_RESOLVERS = <<-EOS
6
+
7
+ # Define how parameter names are mapped to domain
8
+ #
9
+ # SCHEMA:
10
+ #
11
+ # resolvers:
12
+ # - type: <resolver load type>
13
+ # file: <file name in cnf-dir>
14
+ # url: <path or url>
15
+ #
16
+ # <resolver load type>: resolver loader type, valid values: [ 'resolver_yaml' ]
17
+ # <file name in cnf-dir>: file name in cnf-directory
18
+ # <path or url>: path relative to cwd, or http url
19
+ #
20
+ #
21
+ # COMMENTS:
22
+ # - give 'file' xor 'url' property
23
+ #
24
+
25
+ EOS
26
+
27
+ SBUILBER_INTERFACES = <<-EOS
28
+
29
+ # Define how to load interfaces configuration
30
+ #
31
+ # SCHEMA:
32
+ #
33
+ # interfaces:
34
+ # - type: <interface loader type>
35
+ #
36
+ # file: <file name in cnf-dir>
37
+ # infrastructureServices: <is infrastructureService>
38
+ # url: <path or url>
39
+ # cache: <cache file path>
40
+ #
41
+ # <interface loader type>: interface loader type, valid values: [ 'swagger' ]
42
+ # <is infrastructureService>: true or false (default false)
43
+ # <file name in cnf-dir> : file name in cnf-directory
44
+ # <path or url> : path relative to cwd, or http url,
45
+ # e.g https://cdn.rawgit.com/swagger-api/swagger-spec/master/examples/v2.0/yaml/petstore-expanded.yaml
46
+ # <cache file path> : path relative to cwd, where interface file is cached
47
+ #
48
+ # COMMENTS:
49
+ # - give 'file' xor 'url' property
50
+ # - property 'cache' optional, useful when http access slow
51
+ # - infrastructureServices are modelled as procedures, which may modify state
52
+ # or return values used in 'normal' interfaces
53
+ #
54
+
55
+ EOS
56
+
57
+
58
+ SBUILER_SETUPS = <<-EOS
59
+
60
+ # Define environment setups
61
+ #
62
+ # SCHEMA:
63
+ # setups:
64
+ # - setupDirectory: <setupname>
65
+ # extensions:
66
+ # file: <file name in cnf-dir>
67
+ # url: <path or url>
68
+ # preferences:
69
+ # <hash-values>
70
+ #
71
+ # <setupname> : name of setup = sub directory under <gen_dir>
72
+ # <file name in cnf-dir>: name extension configurion file in cnf-directory
73
+ # <path or url> : relative name or url of configurion file
74
+ # <hash-values> : optional properties overriding global generate preferences
75
+ #
76
+ # COMMENTS:
77
+ # - preferences property is optional
78
+ EOS
79
+
80
+ SBUILDER_GENERATE = <<-EOS
81
+ # Generate definitions
82
+ #
83
+ # SCHEMA:
84
+ # generate:
85
+ # - output: <path>
86
+ # inputs:
87
+ #
88
+ # - desc: <description text>
89
+ # modelData: none
90
+ # template: markdown-header.mustache
91
+ # input: <name-of-template>
92
+ #
93
+ # <path>: relative path under <gen-directory>
94
+ # <description text>: text avaiblable for template in {{META.desc}} property
95
+ # <name-of-template>: name of file to output into <path>
96
+ #
97
+ # COMMENTS:
98
+ # - can be used to render also model data using mustache template
99
+ # in this case
100
+ # modelData : <model-data>, where
101
+ # valid values for <model-data>: ['none', 'interfaces', 'steps',
102
+ # 'definitions','domains' ],
103
+ # see document <gen_dir>/<setup>/doc/data-model.md for content
104
+ # template: <mustache-template>, where
105
+ # <mustache-template> is a file <src_dir>
106
+ #
107
+ EOS
108
+
109
+ SBUILDER_PREFERENCES = <<-EOS
110
+ # Generate preferences
111
+ #
112
+ # preferences:
113
+ # <hash-values>
114
+ #
115
+ # <hash-values> optional properties passes to templates in 'PREFERENCES' -property
116
+ #
117
+ # Default templates use following propeties
118
+ # debug-output: <true/false>, output call message in interface processes, default 'true'
119
+ #
120
+ EOS
121
+
122
+
123
+ EXTENSION_HEADER_DOM = <<-EOS
124
+
125
+ # Define extension for domains
126
+ #
127
+ # SCHEMA:
128
+ # - domain-extension:
129
+ # - domain: <domain-name>
130
+ # cardinality: <cardinality>
131
+ # values:
132
+ # - <str-value>
133
+ #
134
+ #
135
+ # <domain-name>: domain name resolved
136
+ # <cardinality>: integer value for domain, default 1
137
+ # <str-value>: fixed value for domain
138
+ #
139
+ # COMMENTS:
140
+ # - give 'cardinality' xor 'values' property
141
+ #
142
+
143
+ EOS
144
+
145
+ EXTENSION_HEADER_IF = <<-EOS
146
+
147
+ # Define name of extension point for interface
148
+ #
149
+ # SCHEMA:
150
+ # - interface-extension:
151
+ # - matcher: <string-or-regex>
152
+ # implementation: <name-implmentation>
153
+ #
154
+ # <string-or-regex>: string or regexp matching inteface
155
+ # example regex !ruby/regexp /customer?\(post\)/ matches
156
+ # customers(post) and customer(post)
157
+ # <name-of-implementation>: must define macro 'p_<name-of-implementation>'
158
+
159
+ EOS
160
+
161
+ EXTENSION_HEADER_SETUP = <<-EOS
162
+
163
+ # Define environment steps
164
+ #
165
+ # SCHEMA:
166
+ # - step-extension:
167
+ # - interface: <interface-name>
168
+ # bindExact: true
169
+ # input:
170
+ # <input>
171
+ # inputs:
172
+ # - input:
173
+ # <input>
174
+ #
175
+ #
176
+ # <interface-name>: name of interface to call in step, e.g. customer(post)
177
+ # <input>: parameter bindings for interface. See 'sbuilder.rb example pet'
178
+ # and `sbuilder.rb example customer` for examples.
179
+ #
180
+ #
181
+ # COMMENTS:
182
+ # - give 'inputs' xor 'input' (first level hash)
183
+ # - 'bindExact' optional,
184
+ # - use 'bindExact': true when input range for interface
185
+ # becomes so big that TLA+ model checker slows down when
186
+ # evaluating the input domain range.
187
+ # - When 'bindExact': true all fields for 'input' property must
188
+ # be given value. Hint use '_default' property in <input>
189
+ # - Hint: use 'inputs' when 'bindExact': true use 'inputs' to
190
+ # allow non-determinism in process input .
191
+ #
192
+
193
+
194
+ EOS
195
+
196
+
197
+ RESOLVER_HEADER = <<-EOS
198
+ # Example of an YAML resolver
199
+ #
200
+ # Contains array of hashes
201
+ #
202
+ # - Name: <name of resolver>
203
+ # Matcher: <string/regexp to match a paramset name to resolve>
204
+ # Rules: <array of RULE-ELEMENTS>
205
+ #
206
+ # RULE-ELEMENT: MATCHER | INCLUDE-MAPPER
207
+ #
208
+ # INCLUDE-MAPPER: hash with Include attribute
209
+ # Include: <name of mapper>
210
+ #
211
+ # MATCHER: hash of with Matcher/Domain attributes
212
+ # Matcher: <string/regexpp to match paramenter id>
213
+ # use !ruby/regexp modifier for a value to make it
214
+ # to a regular expression. For exapmle
215
+ #
216
+ # Matcher: !ruby/regexp /.*/
217
+ #
218
+ # Domain: domain to assign to parameter
219
+ #
220
+ EOS
221
+
222
+
223
+
224
+ end
225
+
226
+ end
@@ -0,0 +1,298 @@
1
+ require 'thor'
2
+
3
+ require_relative '../sbuilder'
4
+
5
+ module Sbuilder
6
+
7
+ class Cli < Thor
8
+
9
+
10
+ include Sbuilder::Utils::MyLogger # mix logger
11
+ PROGNAME = "main" # logger progname
12
+
13
+ VERSION_BANNER = <<-EOS.unindent
14
+ #{File.basename $0} - #{Sbuilder::version}
15
+ EOS
16
+
17
+ # ------------------------------------------------------------------
18
+ # make two thor tasks share options?
19
+ # http://stackoverflow.com/questions/14346285/how-to-make-two-thor-tasks-share-options
20
+
21
+ class << self
22
+ def add_shared_option(name, options = {})
23
+ @shared_options = {} if @shared_options.nil?
24
+ @shared_options[name] = options
25
+ end
26
+
27
+ def shared_options(*option_names)
28
+ option_names.each do |option_name|
29
+ opt = @shared_options[option_name]
30
+ raise "Tried to access shared option '#{option_name}' but it was not previously defined" if opt.nil?
31
+ yield option_name, opt if block_given?
32
+ option option_name, opt
33
+ end
34
+ end
35
+ end
36
+
37
+
38
+ # ------------------------------------------------------------------
39
+ # constructore
40
+
41
+ def initialize(*args)
42
+ super
43
+ @logger = getLogger( PROGNAME, options )
44
+ end
45
+
46
+ # ------------------------------------------------------------------
47
+ # class options
48
+
49
+ class_option :log, :aliases => "-l", :type =>:string, :default => nil,
50
+ :enum => [ "DEBUG", "INFO", "WARN", "ERROR" ],
51
+ :desc => "Set debug level "
52
+
53
+ class_option :logfile, :type =>:string,
54
+ :default => File.join(Dir.getwd, Sbuilder::Constants::LOGFILE), :desc => "Set file for log output"
55
+
56
+
57
+ # ------------------------------------------------------------------
58
+ # shared options
59
+
60
+ add_shared_option :verbosity, :aliases => "-v", :type =>:numeric, :default => Sbuilder::Constants::OPT_VERBOSITY,
61
+ :desc => "Output verbosity range 0-2 (nothing- a lot)"
62
+ add_shared_option :cnf_dir, :aliases => "-C", :type =>:string, :default => Sbuilder::Constants::CNF_DIR,
63
+ :desc => "Configuration directory"
64
+ add_shared_option :src_dir, :aliases => "-S", :type =>:string, :default => Sbuilder::Constants::SRC_DIR,
65
+ :desc => "Source directory for TLA+ snippets"
66
+ add_shared_option :gen_dir, :aliases => "-G", :type =>:string, :default => Sbuilder::Constants::GEN_DIR,
67
+ :desc => "Generation output directory"
68
+ add_shared_option :cache_dir, :aliases => "-T", :type =>:string, :default => Sbuilder::Constants::CACHE_DIR,
69
+ :desc => "Cache directory"
70
+
71
+ add_shared_option :templates, :aliases => "-t", :type => :array, :default => [Sbuilder::Constants::SRC_PATH, Sbuilder::Constants::TEMPLATE_PATH],
72
+ :desc => "Location of TLA+ snippets (accessible in template generation)"
73
+
74
+ add_shared_option :default_templates, :aliases => "-d", :type => :array, :default => [Sbuilder::Constants::TEMPLATE_GEM],
75
+ :desc => "Location of (default) GEM templates"
76
+ add_shared_option :cnf_file, :aliases => "-c", :type => :string, :default => Sbuilder::Constants::CNF_FILE,
77
+ :desc => "Main configuration file (in [--cnf-dir])"
78
+
79
+ # ------------------------------------------------------------------
80
+ # require after shared options added, before subcommand
81
+
82
+ require_relative 'cli-example'
83
+
84
+
85
+
86
+ # ------------------------------------------------------------------
87
+ # action 'config'
88
+ desc "example SUBCOMMAND", "Configuration instructions"
89
+ shared_options :cnf_dir
90
+ shared_options :src_dir
91
+ shared_options :verbosity
92
+ subcommand "example", Example
93
+
94
+ # # ------------------------------------------------------------------
95
+ # #
96
+ # require_relative 'cli-unmustache'
97
+
98
+ # desc "unmustache", "Preprocess mustache files"
99
+ # shared_options :src_dir
100
+ # shared_options :cache_dir
101
+ # subcommand "unmustache", Unmustache
102
+
103
+
104
+ # ------------------------------------------------------------------
105
+ # action load
106
+ # desc :load, "Load configurations"
107
+ # def load()
108
+ # ctrl = getController( options )
109
+ # ctrl.load
110
+ # end
111
+
112
+ # make default task to be version
113
+ default_task :version
114
+
115
+ # ------------------------------------------------------------------
116
+ # action init - create directories
117
+ desc :extend, "Create TLA extension templates under '<src_dir>/extend' directory, and application templates into '<src>' directory"
118
+ shared_options :src_dir
119
+ option :benchmark, :aliases => "-b", :type =>:string, :default => nil,
120
+ :desc => "Include mustache partial call to benchmark directories into TLA template"
121
+ def extend()
122
+
123
+
124
+ Dir.glob( File.join File.dirname( __FILE__), "../../src-extend/extend/extend_*.*" ).each do |extendTemplate|
125
+ extend_files( "#{options[:src_dir]}/extend", extendTemplate, options[:benchmark] )
126
+ end
127
+
128
+ Dir.glob( File.join File.dirname( __FILE__), "../../src-extend/extend_app/*" ).each do |extendTemplate|
129
+ extend_files( "#{options[:src_dir]}", extendTemplate )
130
+ end
131
+
132
+ end
133
+
134
+ # ------------------------------------------------------------------
135
+ # action init - create directories
136
+ desc :version, "Output version"
137
+ def version()
138
+ puts VERSION_BANNER
139
+ end
140
+
141
+
142
+
143
+ # ------------------------------------------------------------------
144
+ # action init - create directories
145
+ desc :init, "Init configuration directories"
146
+ shared_options :cnf_dir
147
+ shared_options :src_dir
148
+ shared_options :cache_dir
149
+ shared_options :gen_dir
150
+ def init()
151
+
152
+ init_dirs( options )
153
+ init_files( options )
154
+
155
+
156
+ end # init
157
+
158
+ desc "generate [SETUP]", "Generates specification for [SETUP], defaults all setups"
159
+ shared_options :templates
160
+ shared_options :default_templates
161
+ shared_options :verbosity
162
+ shared_options :cnf_dir
163
+ shared_options :cnf_file
164
+ # shared_options :src_dir
165
+ shared_options :cache_dir
166
+ shared_options :gen_dir
167
+
168
+ option :filter_src, :aliases => "-f", :type => :boolean, :default => false,
169
+ :desc => "Filter files TLA+ specification code, false-> no filter->include all snippets"
170
+
171
+
172
+ option :filter_list, :aliases => "-F", :type => :string, :default => nil,
173
+ :desc => "List of files to include in TLA+ specification code"
174
+
175
+ def generate( setupDirectory=nil)
176
+ ctrl = getController( options )
177
+ ctrl.setup( setupDirectory )
178
+ end
179
+
180
+ # ------------------------------------------------------------------
181
+ # list
182
+
183
+ desc "list setups", "Lists setup"
184
+ shared_options :verbosity
185
+ shared_options :cnf_dir
186
+ def list( what )
187
+ whats = [ "setups", "setup" ]
188
+ raise <<-EOS unless whats.include?( what )
189
+ Unknown command 'list #{what}'
190
+
191
+ Valid list targets: #{whats.join(',')}
192
+ EOS
193
+
194
+ ctrl = getController( options )
195
+ ctrl.load
196
+ puts "#{ctrl.getSetups().map { |setup| setup['setupDirectory']}.join(' ')}"
197
+ end
198
+
199
+
200
+
201
+ # ------------------------------------------------------------------
202
+ # common routines
203
+ no_commands do
204
+
205
+ # Copy 'extendFile' file to 'dirPath', append {{>benchmark/basename(extendFile}}
206
+ #
207
+ # @param dirPath [String] directory where extension file created
208
+ # @param extendFile [String] path to file, which copy to 'dirPath'
209
+ # @param benchmark [String] optional benchmark directory where load partial templates
210
+ def extend_files( dirPath, extendFile, benchmark=nil )
211
+
212
+ raise "No such directory <src_dir>/extend (#{dirPath})" unless File.exist?( dirPath )
213
+
214
+ @logger.info( "#{__method__} extend file=#{File.basename( extendFile )}" )
215
+ targetPath = "#{dirPath}/#{File.basename( extendFile )}"
216
+ msg = "Extension template #{targetPath}"
217
+ if File.exists?( targetPath) then
218
+ msg += " already exists - not created"
219
+ else
220
+ msg += " does not exist - created"
221
+ FileUtils.cp( extendFile, targetPath )
222
+
223
+ if benchmark then
224
+ partial_call = <<-EOS
225
+
226
+ {{! Benchmark option in extend command defined --> added call to partial in benchmark directory }}
227
+ {{>#{benchmark}/benchmark-#{File.basename(extendFile)} }}
228
+
229
+ EOS
230
+
231
+ # append mustache partitial call
232
+ open( targetPath, 'a' ) { |f|
233
+ f.puts( partial_call )
234
+ }
235
+ end
236
+ end
237
+
238
+ @logger.info( "#{__method__} #{msg}" )
239
+ puts msg
240
+
241
+ end
242
+
243
+ # ------------------------------------------------------------------
244
+
245
+ def init_files( options )
246
+
247
+ [
248
+ { :file => "#{options[:cnf_dir]}/#{Sbuilder::Constants::CNF_FILE }.example", :content => [ Sbuilder::CliCustomer::SBUILDER_YAML_CUSTOMER] },
249
+ { :file => "#{options[:cnf_dir]}/#{Sbuilder::CliCustomer::FILE_RESOLVER_CUSTOMER}.example", :content => [ Sbuilder::CliCustomer::RESOLVER_CUSTOMER] },
250
+ { :file => "#{options[:cnf_dir]}/#{Sbuilder::CliCustomer::FILE_EXTENSIONS_CUSTOMER_COMMON}.exmaple", :content => [Sbuilder::CliCustomer::EXTENSIONS_CUSTOMER_COMMON] },
251
+ { :file => "#{options[:cnf_dir]}/#{Sbuilder::CliCustomer::FILE_EXTENSIONS_CUSTOMER_RUN1}.example", :content => [Sbuilder::CliCustomer::EXTENSIONS_CUSTOMER_RUN1] },
252
+ { :file => "#{options[:cnf_dir]}/#{Sbuilder::CliCustomer::FILE_EXTENSIONS_CUSTOMER_RUN2}.example", :content => [Sbuilder::CliCustomer::EXTENSIONS_CUSTOMER_RUN2] },
253
+ { :file => "#{options[:cnf_dir]}/#{Sbuilder::CliCustomer::FILE_INTERFACE_CUSTOMER}.example", :content => [Sbuilder::CliCustomer::INTERFACE_CUSTOMER_SWAGGER] },
254
+
255
+ ].each do |example|
256
+ puts "File #{example[:file]} - created"
257
+ File.open( example[:file] ,'w' ) { |f| example[:content].each { |lines| f.write( lines )} }
258
+ end
259
+
260
+ end # init files
261
+
262
+ # ------------------------------------------------------------------
263
+ #
264
+ def init_dirs( options )
265
+ [
266
+ options[:cnf_dir],
267
+ options[:cache_dir],
268
+ options[:src_dir],
269
+ "#{options[:src_dir]}/extend",
270
+ options[:gen_dir],
271
+
272
+ ].each do |dir|
273
+ if ! File.exists?( dir ) then
274
+ puts "Directory #{dir} - created"
275
+ Dir.mkdir( dir )
276
+ else
277
+ puts "Directory #{dir} - already exists - no need to create"
278
+ end
279
+
280
+ end
281
+ end # init dirs
282
+
283
+ # DRY method to get controller
284
+ def getController( opts )
285
+ Sbuilder::Controller.new( getFactory( opts ), opts )
286
+ end
287
+
288
+ # DRY method to get factory
289
+ def getFactory( opts )
290
+ Sbuilder::Factory.getFactory( opts )
291
+ end
292
+
293
+ end # no_command
294
+
295
+ end # class Cli
296
+
297
+ end # module
298
+