power_stencil 0.8.13 → 0.9.3

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -15
  3. data/doc/faq.md +4 -7
  4. data/doc/git_integration.md +38 -12
  5. data/etc/meta_templates/plugin_seed/.gitignore +12 -0
  6. data/etc/meta_templates/plugin_seed/.gitlab-ci.yml +11 -0
  7. data/etc/meta_templates/plugin_seed/README.md +20 -5
  8. data/etc/meta_templates/plugin_seed/etc/plugin_capabilities.yaml +3 -0
  9. data/etc/meta_templates/plugin_seed/psplugin_{entity}.gemspec +2 -0
  10. data/etc/meta_templates/plugin_seed/spec/project_helper.rb +50 -0
  11. data/etc/meta_templates/plugin_seed/spec/spec_helper.rb +2 -1
  12. data/etc/meta_templates/plugin_seed/spec/{entity}_spec.rb +21 -1
  13. data/etc/power_stencil.yaml +6 -1
  14. data/etc/templates/plugin_definition/.gitignore +2 -1
  15. data/etc/templates/plugin_definition/.gitlab-ci.yml +11 -0
  16. data/etc/templates/plugin_definition/README.md +20 -5
  17. data/etc/templates/plugin_definition/etc/plugin_capabilities.yaml +3 -0
  18. data/etc/templates/plugin_definition/psplugin_{entity}.gemspec +2 -0
  19. data/etc/templates/plugin_definition/spec/project_helper.rb +50 -0
  20. data/etc/templates/plugin_definition/spec/spec_helper.rb +2 -1
  21. data/etc/templates/plugin_definition/spec/{entity}_spec.rb +21 -1
  22. data/etc/templates/project/.ps_project/versioned-config.yaml +1 -0
  23. data/etc/templates/zsh_command_line_completion/_power_stencil.sh.erb +18 -8
  24. data/lib/power_stencil.rb +4 -0
  25. data/lib/power_stencil/command_processors/adm.rb +29 -1
  26. data/lib/power_stencil/command_processors/create.rb +14 -4
  27. data/lib/power_stencil/dsl/completion.rb +37 -0
  28. data/lib/power_stencil/engine/base.rb +2 -0
  29. data/lib/power_stencil/engine/directory_processor.rb +20 -1
  30. data/lib/power_stencil/engine/project_engine.rb +1 -1
  31. data/lib/power_stencil/engine/renderers/haml.rb +21 -0
  32. data/lib/power_stencil/initializer.rb +6 -1
  33. data/lib/power_stencil/plugins/base.rb +0 -1
  34. data/lib/power_stencil/plugins/capabilities.rb +4 -0
  35. data/lib/power_stencil/plugins/command_line.rb +3 -1
  36. data/lib/power_stencil/plugins/require.rb +6 -6
  37. data/lib/power_stencil/project/base.rb +2 -0
  38. data/lib/power_stencil/project/plugins.rb +35 -2
  39. data/lib/power_stencil/ultra_command_line/command_line_manager.rb +35 -0
  40. data/lib/power_stencil/ultra_command_line/option_definition.rb +5 -0
  41. data/lib/power_stencil/ultra_command_line/providers_manager.rb +21 -0
  42. data/lib/power_stencil/ultra_command_line/sub_command.rb +12 -0
  43. data/lib/power_stencil/utils/completion.rb +19 -9
  44. data/lib/power_stencil/utils/dependency_solver.rb +19 -0
  45. data/lib/power_stencil/version.rb +1 -1
  46. data/power_stencil.gemspec +2 -1
  47. metadata +35 -11
@@ -10,7 +10,9 @@ module PowerStencil
10
10
  clm = PowerStencil.command_line_manager
11
11
  plugin_definition[:processors].each do |processors_name, processor|
12
12
  processor_class = Object.const_get processor
13
- clm.register_processor clm.command_by_alias(processors_name), processor_class.new
13
+ command = clm.command_by_alias(processors_name)
14
+ clm.register_processor command, processor_class.new
15
+ command.add_provider self
14
16
  end
15
17
  end
16
18
 
@@ -7,12 +7,6 @@ module PowerStencil
7
7
 
8
8
  include PowerStencil::Utils::SecureRequire
9
9
 
10
- private
11
-
12
- def module_short_name
13
- name.split(/[-_]+/).map(&:capitalize).join.to_sym
14
- end
15
-
16
10
  def require_entry_point
17
11
  @entry_point_path = File.join plugin_path, 'lib', "#{name.underscore}.rb"
18
12
  logger.debug "Plugin '#{name}' entry point: '#{entry_point_path}'"
@@ -27,6 +21,12 @@ module PowerStencil
27
21
  end
28
22
  end
29
23
 
24
+ private
25
+
26
+ def module_short_name
27
+ name.split(/[-_]+/).map(&:capitalize).join.to_sym
28
+ end
29
+
30
30
  def setup_version
31
31
  @version = PowerStencil::Utils::SemanticVersion.new plugin_module::VERSION
32
32
  capabilities[:version] = true
@@ -1,3 +1,5 @@
1
+ require 'power_stencil/utils/dependency_solver'
2
+
1
3
  require 'power_stencil/project/paths'
2
4
  require 'power_stencil/project/create'
3
5
  require 'power_stencil/project/config'
@@ -18,13 +18,37 @@ module PowerStencil
18
18
 
19
19
  end
20
20
 
21
+ def plugins_sorted_by_dependency
22
+ solver = PowerStencil::Utils::DependencySolver.new
23
+ plugin_names = plugins.keys
24
+
25
+ plugins.each do |_, plugin|
26
+ unless plugin.dependencies.nil?
27
+ plugin.dependencies.each do |dependency_name|
28
+ raise PowerStencil::Error, "Invalid dependency '#{dependency_name}'declared for plugin '#{plugin.name}' !" unless plugin_names.include? dependency_name
29
+ end
30
+ end
31
+ solver[plugin.name] = plugin.dependencies.nil? ? [] : plugin.dependencies
32
+ end
33
+ solver.tsort.map { |plugin_name| plugins[plugin_name] }
34
+ rescue TSort::Cyclic => e
35
+ PowerStencil::Error.report_error e
36
+ raise PowerStencil::Error, 'Plugins cyclical dependency error !'
37
+ end
38
+
39
+
21
40
  private
22
41
 
23
42
  def bootstrap_plugins
24
43
  @plugins = {}
25
44
  initialize_gem_plugins
26
45
  initialize_local_plugins
46
+ require_plugins_entry_points
27
47
  command_line_manager.definition_hash_to_commands
48
+ register_plugins_processors
49
+ end
50
+
51
+ def register_plugins_processors
28
52
  plugins.each do |_, plugin|
29
53
  if plugin.capabilities[:processors]
30
54
  plugin.register_processors
@@ -32,6 +56,12 @@ module PowerStencil
32
56
  end
33
57
  end
34
58
 
59
+ def require_plugins_entry_points
60
+ plugins_sorted_by_dependency.each do |plugin|
61
+ plugin.require_entry_point
62
+ end
63
+ end
64
+
35
65
  def initialize_gem_plugins
36
66
  if config[:project_plugins].empty?
37
67
  PowerStencil.logger.info 'No gem plugin found in project'
@@ -42,7 +72,8 @@ module PowerStencil
42
72
  (gem_name, gem_req) = PowerStencil::Plugins::Base.plugin_definition_to_name_and_req plugin_definition
43
73
  raise PowerStencil::Error, "Plugin '#{gem_name}' already exists !" unless plugins[gem_name].nil?
44
74
 
45
- plugins[gem_name] = PowerStencil::Plugins::Base.new(gem_name, self, type: :gem, gem_req: gem_req)
75
+ plugin = PowerStencil::Plugins::Base.new(gem_name, self, type: :gem, gem_req: gem_req)
76
+ plugins[plugin.name] = plugin
46
77
  end
47
78
  end
48
79
 
@@ -55,10 +86,12 @@ module PowerStencil
55
86
  Dir.entries(project_local_plugins_path)
56
87
  .select { |e| File.directory? File.join(project_local_plugins_path, e) }
57
88
  .reject { |d| %w(. ..).include? d }
89
+ .sort
58
90
  .each do |candidate|
59
91
  begin
60
92
  raise PowerStencil::Error, "Plugin '#{candidate}' already exists !" unless plugins[candidate].nil?
61
- plugins[candidate] = PowerStencil::Plugins::Base.new(candidate, self)
93
+ plugin = PowerStencil::Plugins::Base.new(candidate, self)
94
+ plugins[plugin.name] = plugin
62
95
  rescue PowerStencil::Error => pse
63
96
  logger.puts_and_logs pse.message, logs_as: :error
64
97
  logger.puts_and_logs "Discarding invalid plugin '#{candidate}'.", logs_as: :error
@@ -0,0 +1,35 @@
1
+ class UltraCommandLine::Manager::Base
2
+
3
+ class << self
4
+
5
+ def add_provider_for(command_or_option, provider)
6
+ providers = providers_for command_or_option
7
+ providers << provider unless providers.include? provider
8
+ end
9
+
10
+ def providers_for(command_or_option)
11
+ default_command_data = {options: {}, providers: []}
12
+ case command_or_option
13
+ when UltraCommandLine::Commands::SubCommand
14
+ sc = command_or_option
15
+ internal_provider_mapping[sc.name] ||= default_command_data
16
+ internal_provider_mapping[sc.name][:providers]
17
+ when UltraCommandLine::Commands::OptionDefinition
18
+ sco = command_or_option
19
+ internal_provider_mapping[sco.sub_command.name] ||= default_command_data
20
+ internal_provider_mapping[sco.sub_command.name][:options][sco.name] ||= []
21
+ internal_provider_mapping[sco.sub_command.name][:options][sco.name]
22
+ else
23
+ raise PowerStencil::Error, "Invalid command or option"
24
+ end
25
+ end
26
+
27
+ # private
28
+
29
+ def internal_provider_mapping
30
+ @internal_provider_mapping ||= {}
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,5 @@
1
+ class UltraCommandLine::Commands::OptionDefinition
2
+
3
+ include PowerStencil::UltraCommandLine::ProvidersManager
4
+
5
+ end
@@ -0,0 +1,21 @@
1
+ module PowerStencil
2
+ module UltraCommandLine
3
+
4
+ module ProvidersManager
5
+
6
+ def providers_manager
7
+ PowerStencil.command_line_manager.class
8
+ end
9
+
10
+ def providers
11
+ providers_manager.providers_for self
12
+ end
13
+
14
+ def add_provider(provider)
15
+ providers_manager.add_provider_for self, provider
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ class UltraCommandLine::Commands::SubCommand
2
+
3
+ include PowerStencil::UltraCommandLine::ProvidersManager
4
+
5
+ def add_provider(provider)
6
+ super
7
+ options.each do |option|
8
+ option.add_provider provider
9
+ end
10
+ end
11
+
12
+ end
@@ -3,24 +3,34 @@ module PowerStencil
3
3
 
4
4
  module Completion
5
5
 
6
- include PowerStencil::Utils::DirectoryProcessor
6
+ class FakeIgnoreList
7
+ attr_accessor :return_value
8
+ def ignore_file?(file)
9
+ return_value
10
+ end
11
+ end
7
12
 
8
- def generate_zsh_completion(script_name)
13
+ include PowerStencil::Utils::DirectoryProcessor
9
14
 
10
- # Dirty hack
11
- config.executable_gem_layer[:file_renaming_patterns] = {'(.+)_power_stencil.sh.erb' => '\1_power_stencil' }
15
+ def generate_zsh_completion(script_name, target_file, generating_project_completion)
12
16
 
13
- target_dir = File.expand_path config[:completion_target][:zsh][:completion_dir]
14
17
  source_dir = File.join PowerStencil::Project::Paths.system_templates_templates_path, 'zsh_command_line_completion'
18
+ source_template = File.join source_dir, '_power_stencil.sh.erb'
15
19
 
16
20
  engine = PowerStencil::Engine::InitEngine.new
17
21
  engine.dsl = PowerStencil::Dsl::Completion
18
22
  engine.dsl.script_name = script_name
19
- engine.render_source source_dir, target_dir, overwrite_files: true
23
+ engine.dsl.generating_project_completion = generating_project_completion
24
+
25
+ engine.instance_eval do
26
+ @files_not_to_rename = FakeIgnoreList.new
27
+ files_not_to_rename.return_value = true
28
+ @files_not_to_render = FakeIgnoreList.new
29
+ files_not_to_render.return_value = false
30
+ end
31
+
32
+ engine.render_single_template_file source_template, target_file
20
33
 
21
- puts_and_logs "zsh auto_completion has been installed in '#{File.join target_dir, "_#{script_name}"}'.", check_verbose: false
22
- puts "You should ensure you have something like 'fpath=(#{target_dir} $fpath)' in your ~/.zshrc file..."
23
- puts 'You may have to relog for changes to be applied.'
24
34
  end
25
35
 
26
36
  end
@@ -0,0 +1,19 @@
1
+ require 'tsort'
2
+
3
+ module PowerStencil
4
+ module Utils
5
+
6
+ class DependencySolver < Hash
7
+
8
+ include TSort
9
+
10
+ alias tsort_each_node each_key
11
+
12
+ def tsort_each_child(node, &block)
13
+ fetch(node).each(&block)
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module PowerStencil
2
- VERSION = '0.8.13'.freeze
2
+ VERSION = '0.9.3'.freeze
3
3
  end
@@ -25,11 +25,12 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'rake', '~> 10.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
27
 
28
- spec.add_dependency 'climatic', '~> 0.2.33'
28
+ spec.add_dependency 'climatic', '~> 0.2.34'
29
29
  spec.add_dependency 'dir_glob_ignore', '~> 0.3'
30
30
  spec.add_dependency 'universe_compiler', '~> 0.5.5'
31
31
  spec.add_dependency 'pry'
32
32
  spec.add_dependency 'git' , '~> 1.5.0'
33
+ spec.add_dependency 'haml', '~> 5.1.2'
33
34
 
34
35
  source_code_uri = 'https://gitlab.com/tools4devops/power_stencil'
35
36
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_stencil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.13
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Briais
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-07 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.33
61
+ version: 0.2.34
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.33
68
+ version: 0.2.34
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: dir_glob_ignore
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 1.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: haml
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 5.1.2
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 5.1.2
125
139
  description: PowerStencil is the Swiss-army knife templating workflow for developers
126
140
  and ops.
127
141
  email:
@@ -154,6 +168,8 @@ files:
154
168
  - doc/plugins.md
155
169
  - doc/templates.md
156
170
  - etc/base_commands_definition.yml
171
+ - etc/meta_templates/plugin_seed/.gitignore
172
+ - etc/meta_templates/plugin_seed/.gitlab-ci.yml
157
173
  - etc/meta_templates/plugin_seed/README.md
158
174
  - etc/meta_templates/plugin_seed/etc/command_line.yaml
159
175
  - etc/meta_templates/plugin_seed/etc/plugin_capabilities.yaml
@@ -169,10 +185,12 @@ files:
169
185
  - etc/meta_templates/plugin_seed/lib/{entity}/version.rb.erb
170
186
  - etc/meta_templates/plugin_seed/lib/{entity}/{entity}_processor.rb.erb
171
187
  - etc/meta_templates/plugin_seed/psplugin_{entity}.gemspec
188
+ - etc/meta_templates/plugin_seed/spec/project_helper.rb
172
189
  - etc/meta_templates/plugin_seed/spec/spec_helper.rb
173
190
  - etc/meta_templates/plugin_seed/spec/{entity}_spec.rb
174
191
  - etc/power_stencil.yaml
175
192
  - etc/templates/plugin_definition/.gitignore
193
+ - etc/templates/plugin_definition/.gitlab-ci.yml
176
194
  - etc/templates/plugin_definition/.rspec
177
195
  - etc/templates/plugin_definition/.travis.yml
178
196
  - etc/templates/plugin_definition/CODE_OF_CONDUCT.md
@@ -196,6 +214,7 @@ files:
196
214
  - etc/templates/plugin_definition/lib/{entity}/version.rb.erb
197
215
  - etc/templates/plugin_definition/lib/{entity}/{entity}_processor.rb.erb
198
216
  - etc/templates/plugin_definition/psplugin_{entity}.gemspec
217
+ - etc/templates/plugin_definition/spec/project_helper.rb
199
218
  - etc/templates/plugin_definition/spec/spec_helper.rb
200
219
  - etc/templates/plugin_definition/spec/{entity}_spec.rb
201
220
  - etc/templates/project/.copy_ignore
@@ -245,6 +264,7 @@ files:
245
264
  - lib/power_stencil/engine/init_engine.rb
246
265
  - lib/power_stencil/engine/project_engine.rb
247
266
  - lib/power_stencil/engine/renderers/erb.rb
267
+ - lib/power_stencil/engine/renderers/haml.rb
248
268
  - lib/power_stencil/error.rb
249
269
  - lib/power_stencil/initializer.rb
250
270
  - lib/power_stencil/plugins/base.rb
@@ -282,7 +302,12 @@ files:
282
302
  - lib/power_stencil/system_entity_definitions/project_entity.rb
283
303
  - lib/power_stencil/system_entity_definitions/simple_exec.rb
284
304
  - lib/power_stencil/system_entity_definitions/source_provider.rb
305
+ - lib/power_stencil/ultra_command_line/command_line_manager.rb
306
+ - lib/power_stencil/ultra_command_line/option_definition.rb
307
+ - lib/power_stencil/ultra_command_line/providers_manager.rb
308
+ - lib/power_stencil/ultra_command_line/sub_command.rb
285
309
  - lib/power_stencil/utils/completion.rb
310
+ - lib/power_stencil/utils/dependency_solver.rb
286
311
  - lib/power_stencil/utils/directory_processor.rb
287
312
  - lib/power_stencil/utils/file_edit.rb
288
313
  - lib/power_stencil/utils/file_helper.rb
@@ -302,13 +327,12 @@ metadata:
302
327
  documentation_uri: https://gitlab.com/tools4devops/power_stencil/blob/master/README.md
303
328
  source_code_uri: https://gitlab.com/tools4devops/power_stencil
304
329
  homepage_uri: https://powerstencil.brizone.org/
305
- post_install_message: "\nThank you for installing PowerStencil 0.8.13 !\nFrom the
306
- command line you can run `power_stencil --help`\nIf your shell is not completing
307
- the command:\n If you use rbenv: `rbenv rehash`\n If you use zsh : `rehash`\n\nOfficial
308
- Website : https://powerstencil.brizone.org/\nFull documentation here :
309
- https://gitlab.com/tools4devops/power_stencil/blob/master/README.md\nFeel free to
310
- report issues: https://gitlab.com/tools4devops/power_stencil/issues\n\nType 'power_stencil
311
- adm --zsh-completion' to install auto-completion for zsh.\n\n "
330
+ post_install_message: "\nThank you for installing PowerStencil 0.9.3 !\nFrom the command
331
+ line you can run `power_stencil --help`\nIf your shell is not completing the command:\n
332
+ \ If you use rbenv: `rbenv rehash`\n If you use zsh : `rehash`\n\nOfficial Website
333
+ \ : https://powerstencil.brizone.org/\nFull documentation here : https://gitlab.com/tools4devops/power_stencil/blob/master/README.md\nFeel
334
+ free to report issues: https://gitlab.com/tools4devops/power_stencil/issues\n\nType
335
+ 'power_stencil adm --zsh-completion' to install auto-completion for zsh.\n\n "
312
336
  rdoc_options: []
313
337
  require_paths:
314
338
  - lib