retrospec 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52c998906a997c2915fdcf1f17baeb723e692af9
4
- data.tar.gz: cb788ef2a91361b87f4731d3a1a842df4b540e01
3
+ metadata.gz: 6babe7c886b994aea6dc72564d79fef92170cc78
4
+ data.tar.gz: 8667464aba52550fa565d43f6f7ca5ba3974703d
5
5
  SHA512:
6
- metadata.gz: 26b9a1b0e3b756f3df4151ebb96489b614c59f0f223b71490a421e4f7889752b789b32f04db7d6df4e663d50d934c0a7e85bc6959b8979fb61e5a8e1ded24ee3
7
- data.tar.gz: 1235d95d10a38ddd603904b41d0858bfd5d4b737528289d624459f349d73318e16b139afceacad4da71b39a179ace855376ffe06acdcc9c2d284ed1d82025e4f
6
+ metadata.gz: 3c0ce0d81d0f96193a0b9ae5d1785fde481e69e0c204ca2532a265d812245499ce140d91a068e46028cd2c4d88686d9ee50a108f7b302f532051ff7fa7187643
7
+ data.tar.gz: cec45e06072d9a46ce300528c2b535eea917fd06f12e755fbbf7ac9c109b2b3af9ccd13d849c51621c4a3c879c37e5b6f48753c0867eedf1d8374b1a3e03a466
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -1,4 +1,3 @@
1
- require_relative 'retrospec/module'
2
1
  require_relative 'version'
3
2
  # monkey patch in some color effects string methods
4
3
  class String
@@ -9,6 +9,7 @@ module Retrospec
9
9
 
10
10
  def self.run
11
11
  cli = Retrospec::Cli.new
12
+ # get the list of plugins and provide the plugin name as sub commands
12
13
  sub_commands = cli.plugin_map.keys
13
14
  cmd_help = sub_commands.join("\n")
14
15
 
@@ -30,11 +31,12 @@ Available subcommands:
30
31
  end
31
32
  cmd = ARGV.shift # get the subcommand
32
33
  if plugin_class = cli.plugin_map[cmd]
33
- # run the subcommand options but first send the config file and global options to the subcomamnd
34
- plugin_config = Retrospec::Config.plugin_context(Retrospec::Config.config_data(global_opts[:config_map]), cmd)
35
- cmd_opts = cli.plugin_map[cmd].send(:cli_options, global_opts.merge(plugin_config))
36
- opts = global_opts.merge(cmd_opts)
37
- Retrospec::Module.new(global_opts[:module_path], plugin_class, opts)
34
+ # this is what generates the cli options for the subcommand
35
+ # this is also the main entry point that runs the plugin's cli
36
+ global_config = Retrospec::Config.config_data(global_opts[:config_map])
37
+ plugin_name = plugin_class.send(:plugin_name)
38
+ plugin_config = Retrospec::Config.plugin_context(global_config, plugin_name)
39
+ plugin_class.send(:run_cli, global_opts, global_config, plugin_config)
38
40
  else
39
41
  if global_opts[:available_plugins]
40
42
  Retrospec::Cli.list_available_plugins
@@ -18,6 +18,15 @@ module Retrospec
18
18
  end
19
19
  end
20
20
 
21
+ def safe_move_file(src,dest)
22
+ if File.exists?(dest)
23
+ $stderr.puts "!! #{dest} already exists and differs from template".warning
24
+ else
25
+ FileUtils.mv(src,dest)
26
+ puts " + #{dest}".info
27
+ end
28
+ end
29
+
21
30
  # copy the symlink and preserve the link
22
31
  def safe_create_symlink(src,dest)
23
32
  if File.exists? dest
@@ -39,9 +39,8 @@ module Retrospec
39
39
 
40
40
  # used to display subcommand options to the cli
41
41
  # the global options are passed in for your usage
42
- def self.cli_options(global_opts)
43
- Trollop::options do
44
- end
42
+ def self.run_cli(global_opts, global_config, plugin_config)
43
+ raise NotImplemented
45
44
  end
46
45
 
47
46
  # the name of the plugin that will be sent to the cli
@@ -1,4 +1,4 @@
1
1
  module Retrospec
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
4
4
 
@@ -13,30 +13,66 @@ create a retrospec plugin. Follow the steps below to create a plugin.
13
13
 
14
14
  ## Choosing a plugin name
15
15
  By default the plugin generator will use the name of the directory or the name specified via the -n option. This name
16
- will used through the generator templates so its important to pick a sensible name. The generator also uses the plugin_name
16
+ will be used throughout the generator templates so its important to pick a sensible name. The generator also uses the plugin_name
17
17
  as a class name although you are free to change it after creation.
18
18
 
19
19
  ### Naming the gem and repo
20
20
  Please ensure the gem name uses the following naming scheme retrospec-plugin_name and that your repo is also named retrospec-plugin_name.
21
- This will help everyone identify what the repo and gem do more easily.
21
+ This will help everyone identify what the repo and gem do.
22
22
 
23
23
  Note: puppet-retrospec does not follow this standard due to a legacy name issue that would have caused confusion.
24
24
 
25
25
  ## What you need to override
26
- * run
26
+ * self.run_cli
27
27
 
28
28
  ## Create a context object
29
29
  By default the plugin generator will create a context object that can be used inside templates. The default context object
30
30
  does not contain anything useful so you will want to customize this object only if your templates require variable interpolation.
31
31
 
32
- ## Add custom options to the cli
33
- You can get input from the user in the form of cli options. These options are passed in directly to your init method.
34
- To customize these options please override the the following class method:
32
+ ## Main method to override
33
+ Retrospec will call your plugin by running the plugin.run_cli class method. You can do whatever you want in this method.
35
34
 
36
- ```
37
- def self.cli_options(global_opts)
38
- Trollop::options do
35
+ The global_opts are the options passed into the retrospec command which are specific to retrospec. Additionally, the
36
+ global_config (~/.retrospec/config.yaml) is a hash map of the entire config while the plugin_config is a subset that pertains
37
+ only to your plugin.
38
+
39
+ In this method you should at least call self.new() on your plugin and then plugin_instance.run.
40
+
41
+ For simplicity sake you can also just copy and paste this into your method. This is the default layout when using
42
+ the retrospec plugin generator.
43
+
44
+ ```ruby
45
+ def self.run_cli(global_opts, global_config, plugin_config)
46
+ # a list of subcommands for this plugin
47
+ sub_commands = []
48
+ if sub_commands.count > 0
49
+ sub_command_help = "Subcommands:\n#{sub_commands.join("\n")}\n"
50
+ else
51
+ sub_command_help = ""
52
+ end
53
+ plugin_opts = Trollop::options do
54
+ version "#{Retrospec::Pluginname::VERSION} (c) Your Name"
55
+ banner <<-EOS
56
+ Some description goes here.\n
57
+ #{sub_command_help}
58
+
59
+ EOS
39
60
  opt :option1, "Some fancy option"
61
+ stop_on sub_commands
62
+ end
63
+ # the passed in options will always override the config file
64
+ plugin_data = plugin_opts.merge(global_config).merge(global_opts).merge(plugin_opts)
65
+ # define the default action to use the plugin here, the default is run
66
+ sub_command = (ARGV.shift || :run).to_sym
67
+ # create an instance of this plugin
68
+ plugin = self.new(plugin_data[:module_path],plugin_data)
69
+ # check if the plugin supports the sub command
70
+ if plugin.respond_to?(sub_command)
71
+ plugin.post_init # finish initialization
72
+ plugin.send(sub_command)
73
+ else
74
+ puts "The subcommand #{sub_command} is not supported or valid"
75
+ exit 1
40
76
  end
41
77
  end
42
78
  ```
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "retrospec"
8
- s.version = "0.3.1"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Corey Osman"]
12
- s.date = "2015-09-28"
12
+ s.date = "2015-10-10"
13
13
  s.description = "Retrospec is a framework that allows the automation of repetitive file creation with just about any kind of language through the use of a pluggable architecture."
14
14
  s.email = "corey@logicminds.biz"
15
15
  s.executables = ["retrospec"]
@@ -33,7 +33,6 @@ Gem::Specification.new do |s|
33
33
  "lib/retrospec/cli.rb",
34
34
  "lib/retrospec/config.rb",
35
35
  "lib/retrospec/exceptions.rb",
36
- "lib/retrospec/module.rb",
37
36
  "lib/retrospec/plugin_loader.rb",
38
37
  "lib/retrospec/plugins.rb",
39
38
  "lib/retrospec/plugins/v1.rb",
@@ -1,6 +1,3 @@
1
1
  require 'spec_helper'
2
2
  require 'retrospec'
3
3
 
4
- describe "Retrospec" do
5
- it {expect{Retrospec::Module.new('/Users/cosman/github/puppetlabs-apache', Retrospec::Plugins::V1::Plugin)}.to raise_error NotImplementedError }
6
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retrospec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Osman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-28 00:00:00.000000000 Z
11
+ date: 2015-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -147,7 +147,6 @@ files:
147
147
  - lib/retrospec/cli.rb
148
148
  - lib/retrospec/config.rb
149
149
  - lib/retrospec/exceptions.rb
150
- - lib/retrospec/module.rb
151
150
  - lib/retrospec/plugin_loader.rb
152
151
  - lib/retrospec/plugins.rb
153
152
  - lib/retrospec/plugins/v1.rb
@@ -1,37 +0,0 @@
1
- require_relative 'plugins'
2
- require_relative 'exceptions'
3
- require_relative 'config'
4
-
5
- module Retrospec
6
- class Module
7
- include Retrospec::Plugins
8
- # module path is the relative or absolute path to the module that we should retrofit
9
- # opts hash contains additional flags and options that can be user to control the creation of the tests
10
- # opts[:config_map]
11
- def initialize(supplied_module_path, plugin_class, opts={})
12
- # locates the plugin class that can be used with this module directory
13
- begin
14
- # load any save data in the config file
15
- config_data = Retrospec::Config.config_data(opts[:config_map])
16
- plugin_data = Retrospec::Config.plugin_context(config_data, plugin_class.send(:plugin_name))
17
- # merge the passed in options
18
- plugin_data.merge!(opts)
19
- # create the instance of the plugin
20
- plugin = plugin_class.send(:new, supplied_module_path, plugin_data)
21
- plugin.run
22
- rescue NoSuitablePluginFoundException
23
- puts "No gem was found to support this code type, please install a gem that supports this module.".fatal
24
- end
25
- end
26
-
27
- # finds a suitable plugin given the name of the plugin or via a supported discovery method
28
- def find_plugin_type(module_path, name=nil)
29
- if name
30
- # when the user wants to create a module give the module type
31
- discover_plugin_by_name(name)
32
- else
33
- discover_plugin(module_path)
34
- end
35
- end
36
- end
37
- end