power_stencil 0.8.9 → 0.8.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/etc/meta_templates/plugin_seed/README.md +118 -0
  3. data/etc/meta_templates/plugin_seed/psplugin_{entity}.gemspec +20 -5
  4. data/etc/meta_templates/plugin_seed/spec/spec_helper.rb +15 -0
  5. data/etc/meta_templates/plugin_seed/spec/{entity}_spec.rb +10 -0
  6. data/etc/power_stencil.yaml +1 -0
  7. data/etc/templates/plugin_definition/README.md +95 -20
  8. data/etc/templates/plugin_definition/psplugin_{entity}.gemspec +20 -5
  9. data/etc/templates/plugin_definition/spec/spec_helper.rb +2 -1
  10. data/etc/templates/plugin_definition/spec/{entity}_spec.rb +4 -3
  11. data/etc/templates/zsh_command_line_completion/_power_stencil.sh.erb +18 -8
  12. data/lib/power_stencil.rb +4 -0
  13. data/lib/power_stencil/command_processors/adm.rb +29 -1
  14. data/lib/power_stencil/dsl/completion.rb +37 -0
  15. data/lib/power_stencil/dsl/plugin_generation.rb +4 -0
  16. data/lib/power_stencil/engine/build_handling.rb +5 -0
  17. data/lib/power_stencil/engine/directory_processor.rb +18 -1
  18. data/lib/power_stencil/engine/entities_handling.rb +2 -2
  19. data/lib/power_stencil/initializer.rb +13 -2
  20. data/lib/power_stencil/plugins/command_line.rb +3 -1
  21. data/lib/power_stencil/project/completion.rb +3 -5
  22. data/lib/power_stencil/ultra_command_line/command_line_manager.rb +35 -0
  23. data/lib/power_stencil/ultra_command_line/option_definition.rb +5 -0
  24. data/lib/power_stencil/ultra_command_line/providers_manager.rb +21 -0
  25. data/lib/power_stencil/ultra_command_line/sub_command.rb +12 -0
  26. data/lib/power_stencil/utils/completion.rb +19 -9
  27. data/lib/power_stencil/version.rb +1 -1
  28. data/power_stencil.gemspec +1 -1
  29. metadata +18 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 696922401cd53b56b5b0c902376e0c95093069c8
4
- data.tar.gz: 2ce84bd347b0d55337e72521d47ebdecaa0704f6
3
+ metadata.gz: 953c643a9a919791eeb8dc12c8e725c2a8ab80c6
4
+ data.tar.gz: 8231bae8f9f3d2fe16987b758ffcc8e22be3f295
5
5
  SHA512:
6
- metadata.gz: 8f30eea32756e4c6ff86dd116d36574a8277f027d7641f720d601e55135d435af197d842589c74945280a9367950c3d338525bfdca6e8abd6cffefe915dc80c3
7
- data.tar.gz: 26ad01bce4343dc399553281413fbfaa56331f35b0163ad430273d166aa7aff9811258a54b07ce670f46cad0ce1877c2706a11a778d8c985ab07bebb301512fd
6
+ metadata.gz: dfede811fa8dc0efc67e158abf08e93aac47fb327c6642fff344d6caa0bb7b908443ad31bc229c9b165ab3868c1f311adb63c7d24d168e5fbef98b09495634a4
7
+ data.tar.gz: 1b962bde64576cc9cb8a20f272a048289e42caf212d4fa63814c778fb672e1b0e137ff3dcedb3ecfab6a30488942f1db37e26eceb8b2e687a39156ec13419268
@@ -0,0 +1,118 @@
1
+ <% gem_name = "psplugin_#{ plugin_name}" -%>
2
+ <%= plugin_title_name %>
3
+ <%= '=' * plugin_title_name.size %>
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/<%= gem_name %>.svg)](https://rubygems.org/gems/<%= gem_name %>) [![Pipeline status](https://gitlab.com/tools4devops/psplugins/<%= gem_name %>/badges/master/pipeline.svg)](https://gitlab.com/tools4devops/psplugins/<%= gem_name %>/commits/master)
6
+
7
+ [PowerStencil] is the Swiss-army knife templating workflow for developers and ops.
8
+
9
+ `<%= plugin_title_name %>` is a [PowerStencil] plugin.
10
+
11
+ See [official website][PowerStencil site].
12
+
13
+
14
+ <!-- TOC -->
15
+
16
+ - [What is a PowerStencil plugin ?](#what-is-a-powerstencil-plugin-)
17
+ - [Using this plugin in your `PowerStencil` projects](#using-this-plugin-in-your-powerstencil-projects)
18
+ - [Goal of this plugin](#goal-of-this-plugin)
19
+ - [Plugin capabilities](#plugin-capabilities)
20
+ - [Config](#config)
21
+ - [Subcommands and options](#subcommands-and-options)
22
+ - [Post-build actions](#post-build-actions)
23
+ - [DSL in templates and in `power_stencil shell`](#dsl-in-templates-and-in-power_stencil-shell)
24
+ - [Entity types](#entity-types)
25
+ - [Templates-templates](#templates-templates)
26
+ - [Contributing](#contributing)
27
+ - [License](#license)
28
+ - [Code of Conduct](#code-of-conduct)
29
+
30
+ <!-- /TOC -->
31
+
32
+ # What is a PowerStencil plugin ?
33
+
34
+ A `PowerStencil` plugin can be used in the context of a `PowerStencil` project and bring extra features to a standard project.
35
+
36
+ If you don't know what `PowerStencil` is made for, you may read [the documentation][PowerStencil] first.
37
+
38
+ Features provided by a plugin can be:
39
+
40
+ * Extra config.
41
+ * Extra subcommands or options added to the `power_stencil` command-line.
42
+ * Extra post-build actions.
43
+ * Extra DSL methods available in templates and in `power_stencil shell`.
44
+ * Extra entity types.
45
+ * Extra templates-templates.
46
+
47
+ # Using this plugin in your `PowerStencil` projects
48
+
49
+ To use this plugin within your `PowerStencil` project, you need to:
50
+
51
+ * be within a `PowerStencil` project :wink:.
52
+ * declare this plugin in the project configuration (from the root of your project in the `.ps_project/versioned-config.yaml` file).
53
+
54
+ In this yaml configuration file, you just have to add a new entry in the `:project_plugins` array or simply create it if it is not yet existing:
55
+
56
+ ```yaml
57
+ :project_plugins:
58
+ - <%= gem_name %>
59
+ ```
60
+ If this plugin is not already present on your machine, you may have to download it:
61
+
62
+ $ power_stencil plugin --install
63
+
64
+ And then you may see information about the plugin by running:
65
+
66
+ * `power_stencil info` in the plugins section.
67
+ * `power_stencil plugin --list -v`
68
+
69
+ # Goal of this plugin
70
+
71
+ # Plugin capabilities
72
+
73
+ This plugin provides the following features:
74
+
75
+ ## Config
76
+
77
+ ## Subcommands and options
78
+
79
+ ## Post-build actions
80
+
81
+ ## DSL in templates and in `power_stencil shell`
82
+
83
+ ## Entity types
84
+
85
+ ## Templates-templates
86
+
87
+
88
+ # Contributing
89
+
90
+ Bug reports and pull requests are welcome on Gitlab at https://gitlab.com/tools4devops/psplugins/<%= plugin_name %>/issues. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License].
95
+
96
+ ## Code of Conduct
97
+
98
+ Everyone interacting in the PowerStencil project’s codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct].
99
+
100
+ <!-- End of Document -->
101
+
102
+ <!-- Pages -->
103
+ [code of conduct]: CODE_OF_CONDUCT.md
104
+
105
+ <!-- Code links -->
106
+
107
+ <!-- Illustrations -->
108
+ [simple-flow-image]: doc/images/power-stencil-simple-flow.svg
109
+
110
+ <!-- External links -->
111
+ [MIT License]: http://opensource.org/licenses/MIT "The MIT license"
112
+ [ERB]: https://ruby-doc.org/stdlib-2.6.3/libdoc/erb/rdoc/ERB.html "Quick ERB description"
113
+ [Haml]: http://haml.info/ "The templating engine for XML-like documents"
114
+ [Ruby]: https://www.ruby-lang.org "The powerful Ruby language"
115
+ [Rails]: https://rubyonrails.org/ "The Ruby on Rails framework"
116
+ [PowerStencil site]: https://powerstencil.brizone.org "Official PowerStencil website"
117
+ [PowerStencil]: https://gitlab.com/tools4devops/power_stencil/blob/master/README.md "PowerStencil documentation"
118
+ [PowerStencil plugins]: https://gitlab.com/tools4devops/power_stencil/blob/master/doc/plugins.md "PowerStencil plugins documentation"
@@ -12,13 +12,27 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{<%= plugin_name %> is a plugin for the PowerStencil framework.}
13
13
  spec.description = %q{TODO: Write a longer description or delete this line.}
14
14
  spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
- spec.license = "MIT"
15
+ spec.license = 'MIT'
16
16
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ # Change this and following metadata if you don't want your plugin to be an "official" PowerStencil plugin.
18
+ # ie deployed to https://gitlab.com/tools4devops/psplugins
19
+ source_code_uri = 'https://gitlab.com/tools4devops/psplugins/<%= plugin_name %>'
20
+
21
+ # Gem metadata
19
22
  if spec.respond_to?(:metadata)
23
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
+ # to allow pushing to a single host or delete this line to allow pushing to any host.
20
25
  spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
- # This metadata is mandatory for PowerStencil !!
26
+
27
+ # Nice link to your home page on rubygems.org
28
+ spec.metadata['homepage_uri'] = spec.homepage
29
+
30
+ # You have to probably change this if you don't deploy to gitlab
31
+ spec.metadata['bug_tracker_uri'] = "#{source_code_uri}/issues"
32
+ spec.metadata['documentation_uri'] = "#{source_code_uri}/blob/master/README.md"
33
+ spec.metadata['source_code_uri'] = source_code_uri
34
+
35
+ # This metadata is mandatory for a PowerStencil plugin !!
22
36
  spec.metadata['plugin_name'] = '<%= plugin_name %>'
23
37
  else
24
38
  raise 'RubyGems 2.0 or newer is required to protect against public gem pushes and PowerStencil plugin mechanism !'
@@ -31,8 +45,9 @@ Gem::Specification.new do |spec|
31
45
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
46
  spec.require_paths = ['lib']
33
47
 
34
- spec.add_development_dependency 'bundler', '~> 2.0.2'
48
+ spec.add_development_dependency 'bundler'
35
49
  spec.add_development_dependency 'rake', '~> 10.0'
36
50
  spec.add_development_dependency 'rspec', '~> 3.0'
37
51
  spec.add_development_dependency 'power_stencil', "~> <%= PowerStencil::VERSION %>"
52
+
38
53
  end
@@ -0,0 +1,15 @@
1
+ require "bundler/setup"
2
+ require 'power_stencil'
3
+ require "<%= plugin_name %>"
4
+
5
+ RSpec.configure do |config|
6
+ # Enable flags like --only-failures and --next-failure
7
+ config.example_status_persistence_file_path = ".rspec_status"
8
+
9
+ # Disable RSpec exposing methods globally on `Module` and `main`
10
+ config.disable_monkey_patching!
11
+
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ RSpec.describe <%= plugin_module_name %> do
2
+ it 'has a version number' do
3
+ expect(<%= plugin_module_name %>::VERSION).not_to be nil
4
+ end
5
+
6
+ it 'does something useful' do
7
+ pending 'Tests implementation'
8
+ RSpec.fail
9
+ end
10
+ end
@@ -110,6 +110,7 @@
110
110
  :completion_target:
111
111
  :zsh:
112
112
  :completion_dir: ~/.zsh/completion
113
+ :project_completion_filename: .zsh_project_completion
113
114
 
114
115
 
115
116
 
@@ -1,43 +1,118 @@
1
- # <%= plugin_module_name %>
1
+ <% gem_name = "psplugin_#{ plugin_name}" -%>
2
+ <%= plugin_title_name %>
3
+ <%= '=' * plugin_title_name.size %>
2
4
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/<%= plugin_module_name %>`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ [![Gem Version](https://badge.fury.io/rb/<%= gem_name %>.svg)](https://rubygems.org/gems/<%= gem_name %>) [![Pipeline status](https://gitlab.com/tools4devops/psplugins/<%= gem_name %>/badges/master/pipeline.svg)](https://gitlab.com/tools4devops/psplugins/<%= gem_name %>/commits/master)
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
7
+ [PowerStencil] is the Swiss-army knife templating workflow for developers and ops.
6
8
 
7
- ## Installation
9
+ `<%= plugin_title_name %>` is a [PowerStencil] plugin.
8
10
 
9
- Add this line to your application's Gemfile:
11
+ See [official website][PowerStencil site].
10
12
 
11
- ```ruby
12
- gem '<%= plugin_module_name %>'
13
+
14
+ <!-- TOC -->
15
+
16
+ - [What is a PowerStencil plugin ?](#what-is-a-powerstencil-plugin-)
17
+ - [Using this plugin in your `PowerStencil` projects](#using-this-plugin-in-your-powerstencil-projects)
18
+ - [Goal of this plugin](#goal-of-this-plugin)
19
+ - [Plugin capabilities](#plugin-capabilities)
20
+ - [Config](#config)
21
+ - [Subcommands and options](#subcommands-and-options)
22
+ - [Post-build actions](#post-build-actions)
23
+ - [DSL in templates and in `power_stencil shell`](#dsl-in-templates-and-in-power_stencil-shell)
24
+ - [Entity types](#entity-types)
25
+ - [Templates-templates](#templates-templates)
26
+ - [Contributing](#contributing)
27
+ - [License](#license)
28
+ - [Code of Conduct](#code-of-conduct)
29
+
30
+ <!-- /TOC -->
31
+
32
+ # What is a PowerStencil plugin ?
33
+
34
+ A `PowerStencil` plugin can be used in the context of a `PowerStencil` project and bring extra features to a standard project.
35
+
36
+ If you don't know what `PowerStencil` is made for, you may read [the documentation][PowerStencil] first.
37
+
38
+ Features provided by a plugin can be:
39
+
40
+ * Extra config.
41
+ * Extra subcommands or options added to the `power_stencil` command-line.
42
+ * Extra post-build actions.
43
+ * Extra DSL methods available in templates and in `power_stencil shell`.
44
+ * Extra entity types.
45
+ * Extra templates-templates.
46
+
47
+ # Using this plugin in your `PowerStencil` projects
48
+
49
+ To use this plugin within your `PowerStencil` project, you need to:
50
+
51
+ * be within a `PowerStencil` project :wink:.
52
+ * declare this plugin in the project configuration (from the root of your project in the `.ps_project/versioned-config.yaml` file).
53
+
54
+ In this yaml configuration file, you just have to add a new entry in the `:project_plugins` array or simply create it if it is not yet existing:
55
+
56
+ ```yaml
57
+ :project_plugins:
58
+ - <%= gem_name %>
13
59
  ```
60
+ If this plugin is not already present on your machine, you may have to download it:
61
+
62
+ $ power_stencil plugin --install
63
+
64
+ And then you may see information about the plugin by running:
65
+
66
+ * `power_stencil info` in the plugins section.
67
+ * `power_stencil plugin --list -v`
68
+
69
+ # Goal of this plugin
14
70
 
15
- And then execute:
71
+ # Plugin capabilities
16
72
 
17
- $ bundle
73
+ This plugin provides the following features:
18
74
 
19
- Or install it yourself as:
75
+ ## Config
20
76
 
21
- $ gem install <%= plugin_module_name %>
77
+ ## Subcommands and options
22
78
 
23
- ## Usage
79
+ ## Post-build actions
24
80
 
25
- TODO: Write usage instructions here
81
+ ## DSL in templates and in `power_stencil shell`
26
82
 
27
- ## Development
83
+ ## Entity types
28
84
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
85
+ ## Templates-templates
30
86
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
87
 
33
- ## Contributing
88
+ # Contributing
34
89
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/<%= plugin_module_name %>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
90
+ Bug reports and pull requests are welcome on Gitlab at https://gitlab.com/tools4devops/psplugins/<%= plugin_name %>/issues. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
91
 
37
92
  ## License
38
93
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
94
+ The gem is available as open source under the terms of the [MIT License].
40
95
 
41
96
  ## Code of Conduct
42
97
 
43
- Everyone interacting in the <%= plugin_module_name %> project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/<%= plugin_module_name %>/blob/master/CODE_OF_CONDUCT.md).
98
+ Everyone interacting in the PowerStencil project’s codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct].
99
+
100
+ <!-- End of Document -->
101
+
102
+ <!-- Pages -->
103
+ [code of conduct]: CODE_OF_CONDUCT.md
104
+
105
+ <!-- Code links -->
106
+
107
+ <!-- Illustrations -->
108
+ [simple-flow-image]: doc/images/power-stencil-simple-flow.svg
109
+
110
+ <!-- External links -->
111
+ [MIT License]: http://opensource.org/licenses/MIT "The MIT license"
112
+ [ERB]: https://ruby-doc.org/stdlib-2.6.3/libdoc/erb/rdoc/ERB.html "Quick ERB description"
113
+ [Haml]: http://haml.info/ "The templating engine for XML-like documents"
114
+ [Ruby]: https://www.ruby-lang.org "The powerful Ruby language"
115
+ [Rails]: https://rubyonrails.org/ "The Ruby on Rails framework"
116
+ [PowerStencil site]: https://powerstencil.brizone.org "Official PowerStencil website"
117
+ [PowerStencil]: https://gitlab.com/tools4devops/power_stencil/blob/master/README.md "PowerStencil documentation"
118
+ [PowerStencil plugins]: https://gitlab.com/tools4devops/power_stencil/blob/master/doc/plugins.md "PowerStencil plugins documentation"
@@ -12,13 +12,27 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{<%= plugin_name %> is a plugin for the PowerStencil framework.}
13
13
  spec.description = %q{TODO: Write a longer description or delete this line.}
14
14
  spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
- spec.license = "MIT"
15
+ spec.license = 'MIT'
16
16
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ # Change this and following metadata if you don't want your plugin to be an "official" PowerStencil plugin.
18
+ # ie deployed to https://gitlab.com/tools4devops/psplugins
19
+ source_code_uri = 'https://gitlab.com/tools4devops/psplugins/<%= plugin_name %>'
20
+
21
+ # Gem metadata
19
22
  if spec.respond_to?(:metadata)
23
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
+ # to allow pushing to a single host or delete this line to allow pushing to any host.
20
25
  spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
- # This metadata is mandatory for PowerStencil !!
26
+
27
+ # Nice link to your home page on rubygems.org
28
+ spec.metadata['homepage_uri'] = spec.homepage
29
+
30
+ # You have to probably change this if you don't deploy to gitlab
31
+ spec.metadata['bug_tracker_uri'] = "#{source_code_uri}/issues"
32
+ spec.metadata['documentation_uri'] = "#{source_code_uri}/blob/master/README.md"
33
+ spec.metadata['source_code_uri'] = source_code_uri
34
+
35
+ # This metadata is mandatory for a PowerStencil plugin !!
22
36
  spec.metadata['plugin_name'] = '<%= plugin_name %>'
23
37
  else
24
38
  raise 'RubyGems 2.0 or newer is required to protect against public gem pushes and PowerStencil plugin mechanism !'
@@ -31,8 +45,9 @@ Gem::Specification.new do |spec|
31
45
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
46
  spec.require_paths = ['lib']
33
47
 
34
- spec.add_development_dependency 'bundler', '~> 2.0.2'
48
+ spec.add_development_dependency 'bundler'
35
49
  spec.add_development_dependency 'rake', '~> 10.0'
36
50
  spec.add_development_dependency 'rspec', '~> 3.0'
37
51
  spec.add_development_dependency 'power_stencil', "~> <%= PowerStencil::VERSION %>"
52
+
38
53
  end
@@ -1,5 +1,6 @@
1
1
  require "bundler/setup"
2
- require "<%= plugin_module_name %>"
2
+ require 'power_stencil'
3
+ require "<%= plugin_name %>"
3
4
 
4
5
  RSpec.configure do |config|
5
6
  # Enable flags like --only-failures and --next-failure
@@ -1,9 +1,10 @@
1
1
  RSpec.describe <%= plugin_module_name %> do
2
- it "has a version number" do
2
+ it 'has a version number' do
3
3
  expect(<%= plugin_module_name %>::VERSION).not_to be nil
4
4
  end
5
5
 
6
- it "does something useful" do
7
- expect(false).to eq(true)
6
+ it 'does something useful' do
7
+ pending 'Tests implementation'
8
+ RSpec.fail
8
9
  end
9
10
  end
@@ -2,10 +2,10 @@
2
2
 
3
3
  # zsh shell completion script for <%= script_name %>
4
4
  # To regenerate this file: '<%= script_name %> adm --zsh-completion'
5
- # Generated on the <%= Time.now %> by <%= script_name %> v<%= PowerStencil::VERSION %>
5
+ # Generated<%= timestamp %> by <%= script_name %> v<%= PowerStencil::VERSION %>
6
6
 
7
- <% commands = PowerStencil.command_line_manager.commands -%>
8
- _<%= script_name %>() {
7
+ <% commands = context_commands -%>
8
+ _<%= script_name %>_first_level() {
9
9
  local cmd
10
10
  local <%= script_name %>_sub_commands
11
11
  <%= script_name %>_sub_commands=(<%= commands.reject { |c| c.name.empty? }.sort { |a,b| a.name <=> b.name }.map(&:name).join ' ' %>)
@@ -21,7 +21,7 @@ _<%= script_name %>() {
21
21
  (( $+functions[_<%= script_name %>_cmd_$cmd] )) && _<%= script_name %>_cmd_$cmd
22
22
  else
23
23
  _values : \
24
- <%= continued_multilines(root_command(commands).options.sort { |a,b| a.name <=> b.name }.map {|o| option_representation o}, number_spaces: 10) %>
24
+ <%= continued_multilines(context_options(root_command commands).sort { |a,b| a.name <=> b.name }.map {|o| option_representation o}, number_spaces: 10) %>
25
25
  fi
26
26
  else
27
27
  _values : \
@@ -33,7 +33,7 @@ _<%= script_name %>() {
33
33
  <% end -%>
34
34
  <%= command_representation command %> \
35
35
  <% end -%>
36
- <%= continued_multilines(root_command.options.sort { |a,b| a.name <=> b.name }.map {|o| option_representation o}, number_spaces: 8) %>
36
+ <%= continued_multilines(context_options(root_command).sort { |a,b| a.name <=> b.name }.map {|o| option_representation o}, number_spaces: 8) %>
37
37
  fi
38
38
  }
39
39
 
@@ -46,7 +46,7 @@ _<%= script_name %>_cmd_<%= command.name %>() {
46
46
  _arguments -s : \
47
47
  <%
48
48
  command_param = default_command_param_type command
49
- options_lines = command.options.sort { |a,b| a.name <=> b.name }.map {|o| option_representation o}
49
+ options_lines = context_options(command).sort { |a,b| a.name <=> b.name }.map {|o| option_representation o}
50
50
  options_lines << command_param unless command_param.empty?
51
51
  -%>
52
52
  <%= continued_multilines(options_lines) %>
@@ -124,5 +124,15 @@ _power_stencil_do_nothing() {
124
124
  return 1
125
125
  }
126
126
 
127
- # Let's rock
128
- _<%= script_name %> "$@"
127
+
128
+ _<%= script_name %>() {
129
+ if $( _within_power_stencil_project ); then
130
+ local project_root=$( _power_stencil_project_root )
131
+ if [ -f "${project_root}/.ps_project/<%= PowerStencil.config[:completion_target][:zsh][:project_completion_filename] %>" ]; then
132
+ . "${project_root}/.ps_project/<%= PowerStencil.config[:completion_target][:zsh][:project_completion_filename] %>"
133
+ fi
134
+ else
135
+ . "<%= File.expand_path(File.join PowerStencil.config[:completion_target][:zsh][:completion_dir], "_#{script_name}") %>"
136
+ fi
137
+ _<%= script_name %>_first_level "$@"
138
+ }
@@ -5,6 +5,10 @@ require 'dir_glob_ignore'
5
5
 
6
6
  $DO_NOT_AUTOSTART_CLIMATIC=true
7
7
  require 'climatic'
8
+ require 'power_stencil/ultra_command_line/command_line_manager'
9
+ require 'power_stencil/ultra_command_line/providers_manager'
10
+ require 'power_stencil/ultra_command_line/option_definition'
11
+ require 'power_stencil/ultra_command_line/sub_command'
8
12
 
9
13
  require 'power_stencil/error'
10
14
  require 'power_stencil/utils/os'
@@ -12,7 +12,35 @@ module PowerStencil
12
12
  def execute
13
13
 
14
14
  if config[:'zsh-completion']
15
- generate_zsh_completion 'power_stencil'
15
+ target_dir = File.expand_path config[:completion_target][:zsh][:completion_dir]
16
+ script_name = 'power_stencil'
17
+ user_completion_script = File.join target_dir, "_#{script_name}"
18
+ begin
19
+ current_dir = Dir.pwd
20
+ Dir.mktmpdir 'completion_generation' do |tmpdir|
21
+ Dir.chdir tmpdir
22
+ generate_zsh_completion script_name, user_completion_script, false
23
+ end
24
+ ensure
25
+ Dir.chdir current_dir
26
+ end
27
+
28
+ begin
29
+ project
30
+ shortname_project_completion_script = File.join config[:default_config_directory_name], config[:completion_target][:zsh][:project_completion_filename]
31
+ project.track_action_with_git("Adding project specific zsh completion file: '#{ shortname_project_completion_script }'.") do
32
+ project_completion_script = File.join project.project_config_root, config[:completion_target][:zsh][:project_completion_filename]
33
+ generate_zsh_completion script_name, project_completion_script, true
34
+ puts_and_logs "A specific completion has been generated for this project in '#{project_completion_script}'.", check_verbose: false
35
+ end
36
+ rescue
37
+ # Do not check errors. This is just to load project config...
38
+ logger.debug "Outside of a PowerStencil project... Not generating zsh project completion."
39
+ end
40
+ puts_and_logs "zsh global auto_completion has been installed in '#{user_completion_script}'.", check_verbose: false
41
+ puts
42
+ puts "You should ensure you have something like 'fpath=(#{target_dir} $fpath)' in your ~/.zshrc file..."
43
+ puts 'You may have to relog for changes to be applied.'
16
44
  return
17
45
  end
18
46
 
@@ -5,15 +5,52 @@ module PowerStencil
5
5
 
6
6
  class << self
7
7
  attr_accessor :script_name
8
+ attr_accessor :generating_project_completion
8
9
  end
9
10
 
10
11
  attr_reader :encountered_types
11
12
 
13
+ def timestamp
14
+ if generating_user_completion?
15
+ " on the #{Time.now}"
16
+ else
17
+ ''
18
+ end
19
+ end
20
+
12
21
  def initialize(universe)
13
22
  super
14
23
  @encountered_types = {}
15
24
  end
16
25
 
26
+ def generating_project_completion?
27
+ self.class.generating_project_completion
28
+ end
29
+
30
+ def generating_user_completion?
31
+ !self.class.generating_project_completion
32
+ end
33
+
34
+ def context_commands
35
+ if generating_user_completion?
36
+ PowerStencil.command_line_manager.commands.select do |command|
37
+ command.providers.include? PowerStencil
38
+ end
39
+ else
40
+ PowerStencil.command_line_manager.commands
41
+ end
42
+ end
43
+
44
+ def context_options(command)
45
+ if generating_user_completion?
46
+ command.options.select do |option|
47
+ option.providers.include? PowerStencil
48
+ end
49
+ else
50
+ command.options
51
+ end
52
+ end
53
+
17
54
  def script_name
18
55
  self.class.script_name
19
56
  end
@@ -7,6 +7,10 @@ module PowerStencil
7
7
  main_entry_point.underscore
8
8
  end
9
9
 
10
+ def plugin_title_name
11
+ plugin_name.tr('_', ' ').split.map(&:capitalize).join(' ')
12
+ end
13
+
10
14
  def plugin_module_name
11
15
  plugin_name.camelize
12
16
  end
@@ -95,8 +95,11 @@ module PowerStencil
95
95
 
96
96
 
97
97
  def build_entity(entity_to_build, target_path)
98
+ initial_directory = Dir.pwd
98
99
  target_plugin_name = entity_to_build.buildable_by.to_s
99
100
  default_build entity_to_build, target_path
101
+ # Post processing executed from generated directory (#11)
102
+ Dir.chdir target_path
100
103
 
101
104
  if target_plugin_name.empty?
102
105
  post_build_hook entity_to_build, target_path
@@ -106,6 +109,8 @@ module PowerStencil
106
109
  raise PowerStencil::Error, "Plugin '#{target_plugin_name}' has no build capability !" unless target_plugin.capabilities[:build]
107
110
  target_plugin.post_build_hook entity_to_build, target_path
108
111
  end
112
+ ensure
113
+ Dir.chdir initial_directory
109
114
  end
110
115
 
111
116
  def default_build(entity_to_build, target_path)
@@ -30,10 +30,27 @@ module PowerStencil
30
30
  end
31
31
  end
32
32
  ensure
33
- @rendering_context = nil
33
+ @files_not_to_rename = nil
34
34
  @files_not_to_render = nil
35
35
  end
36
36
 
37
+
38
+ def render_single_template_file(source_template, destination_file, main_entry_point: nil)
39
+ compiled_universe = root_universe.compile scenario: config[:scenario]
40
+ puts_and_logs 'Entities analysis completed.'
41
+
42
+ logger.info 'Generating target file...'
43
+
44
+ process_file source_template, destination_file,
45
+ compiled_universe,
46
+ overwrite_files: true,
47
+ main_entry_point: main_entry_point
48
+ ensure
49
+ @files_not_to_rename = nil
50
+ @files_not_to_render = nil
51
+ end
52
+
53
+
37
54
  private
38
55
 
39
56
  def detemplatized_file_name(filename, replacement_text)
@@ -34,11 +34,11 @@ module PowerStencil
34
34
  @available_entities_hash.keys
35
35
  end
36
36
 
37
- def entity(type, name, universe)
37
+ def entity(type, name, universe = self.root_universe)
38
38
  universe.get_entity type, name
39
39
  end
40
40
 
41
- def entities(universe, criterion: nil, value: nil, &filter_block)
41
+ def entities(universe = self.root_universe, criterion: nil, value: nil, &filter_block)
42
42
  universe.get_entities criterion: criterion, value: value, &filter_block
43
43
  end
44
44
 
@@ -17,6 +17,7 @@ module PowerStencil
17
17
  logger.debug 'Starting PowerStencil initialization...'
18
18
  setup_system_processors
19
19
  setup_universe_compiler_logger
20
+ try_to_load_project fail_on_error: false
20
21
  logger.debug 'PowerStencil initialization complete'
21
22
  end
22
23
 
@@ -29,7 +30,12 @@ module PowerStencil
29
30
  include PowerStencil::Utils::FileHelper
30
31
 
31
32
  def try_to_load_project(fail_on_error: true)
32
- PowerStencil::Project::Base.instantiate_from_config config
33
+ begin
34
+ PowerStencil::Project::Base.instantiate_from_config config
35
+ rescue => e
36
+ raise e if fail_on_error
37
+ end
38
+
33
39
  end
34
40
 
35
41
  def setup_system_processors
@@ -49,14 +55,19 @@ module PowerStencil
49
55
  describe: PowerStencil::CommandProcessors::Describe,
50
56
  adm: PowerStencil::CommandProcessors::Adm
51
57
  }.each do |command_name, processor|
52
- command_line_manager.register_processor command_line_manager.command_by_alias(command_name),
58
+ command = command_line_manager.command_by_alias(command_name)
59
+ command_line_manager.register_processor command,
53
60
  processor.new
61
+ command.add_provider self
54
62
  end
55
63
  end
56
64
 
57
65
  def setup_climatic(cmd_line_args)
58
66
  mngr = Climatic::ConfigLayers::CommandLineLayer.build_command_line_manager base_commands_definition_file
59
67
  Climatic.bootstrap cmd_line_args: cmd_line_args, command_manager: mngr
68
+ mngr.commands.each do |command|
69
+ command.add_provider PowerStencil
70
+ end
60
71
  begin
61
72
  # Fix command line layer priority to allow a bigger number of plugins
62
73
  config.command_line_layer.priority = 999
@@ -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
 
@@ -6,17 +6,15 @@ module PowerStencil
6
6
  def query_for_completion(query_type)
7
7
  case query_type
8
8
  when :entities
9
- engine.entities(engine.root_universe).map(&:as_path).sort
9
+ engine.entities.map(&:as_path).sort
10
10
  when :'entity-types'
11
11
  engine.available_entity_types.sort
12
12
  when :scenario
13
- engine.entities(engine.root_universe, criterion: :by_type, value: :entity_override) do |entity|
13
+ engine.entities(criterion: :by_type, value: :entity_override) do |entity|
14
14
  !entity.scenario.nil? and !entity.scenario.empty?
15
15
  end.map(&:scenario).sort.uniq
16
16
  when :buildable
17
- engine.entities(engine.root_universe) do |entity|
18
- entity.buildable?
19
- end.map(&:as_path).sort
17
+ engine.entities(&:buildable?).map(&:as_path).sort
20
18
  else
21
19
  raise PowerStencil::Error, "'#{query_type}' is not a valid query type for completion !"
22
20
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module PowerStencil
2
- VERSION = '0.8.9'.freeze
2
+ VERSION = '0.8.14'.freeze
3
3
  end
@@ -25,7 +25,7 @@ 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.32'
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'
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.9
4
+ version: 0.8.14
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-06 00:00:00.000000000 Z
11
+ date: 2019-11-09 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.32
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.32
68
+ version: 0.2.34
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: dir_glob_ignore
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -154,6 +154,7 @@ files:
154
154
  - doc/plugins.md
155
155
  - doc/templates.md
156
156
  - etc/base_commands_definition.yml
157
+ - etc/meta_templates/plugin_seed/README.md
157
158
  - etc/meta_templates/plugin_seed/etc/command_line.yaml
158
159
  - etc/meta_templates/plugin_seed/etc/plugin_capabilities.yaml
159
160
  - etc/meta_templates/plugin_seed/etc/plugin_config.yaml
@@ -168,6 +169,8 @@ files:
168
169
  - etc/meta_templates/plugin_seed/lib/{entity}/version.rb.erb
169
170
  - etc/meta_templates/plugin_seed/lib/{entity}/{entity}_processor.rb.erb
170
171
  - etc/meta_templates/plugin_seed/psplugin_{entity}.gemspec
172
+ - etc/meta_templates/plugin_seed/spec/spec_helper.rb
173
+ - etc/meta_templates/plugin_seed/spec/{entity}_spec.rb
171
174
  - etc/power_stencil.yaml
172
175
  - etc/templates/plugin_definition/.gitignore
173
176
  - etc/templates/plugin_definition/.rspec
@@ -279,6 +282,10 @@ files:
279
282
  - lib/power_stencil/system_entity_definitions/project_entity.rb
280
283
  - lib/power_stencil/system_entity_definitions/simple_exec.rb
281
284
  - lib/power_stencil/system_entity_definitions/source_provider.rb
285
+ - lib/power_stencil/ultra_command_line/command_line_manager.rb
286
+ - lib/power_stencil/ultra_command_line/option_definition.rb
287
+ - lib/power_stencil/ultra_command_line/providers_manager.rb
288
+ - lib/power_stencil/ultra_command_line/sub_command.rb
282
289
  - lib/power_stencil/utils/completion.rb
283
290
  - lib/power_stencil/utils/directory_processor.rb
284
291
  - lib/power_stencil/utils/file_edit.rb
@@ -299,12 +306,13 @@ metadata:
299
306
  documentation_uri: https://gitlab.com/tools4devops/power_stencil/blob/master/README.md
300
307
  source_code_uri: https://gitlab.com/tools4devops/power_stencil
301
308
  homepage_uri: https://powerstencil.brizone.org/
302
- post_install_message: "\nThank you for installing PowerStencil 0.8.9 !\nFrom the command
303
- line you can run `power_stencil --help`\nIf your shell is not completing the command:\n
304
- \ If you use rbenv: `rbenv rehash`\n If you use zsh : `rehash`\n\nOfficial Website
305
- \ : https://powerstencil.brizone.org/\nFull documentation here : https://gitlab.com/tools4devops/power_stencil/blob/master/README.md\nFeel
306
- free to report issues: https://gitlab.com/tools4devops/power_stencil/issues\n\nType
307
- 'power_stencil adm --zsh-completion' to install auto-completion for zsh.\n\n "
309
+ post_install_message: "\nThank you for installing PowerStencil 0.8.14 !\nFrom the
310
+ command line you can run `power_stencil --help`\nIf your shell is not completing
311
+ the command:\n If you use rbenv: `rbenv rehash`\n If you use zsh : `rehash`\n\nOfficial
312
+ Website : https://powerstencil.brizone.org/\nFull documentation here :
313
+ https://gitlab.com/tools4devops/power_stencil/blob/master/README.md\nFeel free to
314
+ report issues: https://gitlab.com/tools4devops/power_stencil/issues\n\nType 'power_stencil
315
+ adm --zsh-completion' to install auto-completion for zsh.\n\n "
308
316
  rdoc_options: []
309
317
  require_paths:
310
318
  - lib