lib/retrospec/plugins/v1/plugin/templates/plugin-name.rb.retrospec.erb in retrospec-plugingen-0.2.2 vs lib/retrospec/plugins/v1/plugin/templates/plugin-name.rb.retrospec.erb in retrospec-plugingen-0.3.0

- old
+ new

@@ -1,7 +1,8 @@ require 'retrospec/plugins/v1' require_relative 'spec_object' +require_relative 'version' module Retrospec module Plugins module V1 class <%= capitalized_plugin_name %> < Retrospec::Plugins::V1::Plugin @@ -20,32 +21,61 @@ # used to display subcommand options to the cli # the global options are passed in for your usage # http://trollop.rubyforge.org # all options here are available in the config passed into config object - def self.cli_options(global_opts) - Trollop::options do - opt :option1, "Some fancy option" - end + def self.run_cli(global_opts, global_config, plugin_config, args=ARGV) + # a list of subcommands for this plugin, if any + sub_commands = [] + if sub_commands.count > 0 + sub_command_help = "Subcommands:\n#{sub_commands.join("\n")}\n" + else + sub_command_help = "" end + plugin_opts = Trollop::options do + version "#{Retrospec::<%= capitalized_plugin_name %>::VERSION} (c) Your Name" + banner <<-EOS + A short description of your plugin goes here\n + #{sub_command_help} - # this is the main entry point that retrospec will use to make magic happen - # this is called after everything has been initialized - def run + EOS + opt :option1, "Some Fancy option", :require => false, :short => '-n', :type => :string, + :default => File.basename(File.expand_path(global_opts[:module_path])) + stop_on sub_commands + end + # the passed in options will always override the config file + plugin_data = plugin_opts.merge(global_config).merge(global_opts).merge(plugin_config).merge(plugin_opts) + # define the default action to use the plugin here, the default is run + sub_command = (args.shift || :run).to_sym + # create an instance of this plugin + plugin = self.new(plugin_data[:module_path],plugin_data) + # check if the plugin supports the sub command + if plugin.respond_to?(sub_command) + plugin.send(sub_command) + else + puts "The subcommand #{sub_command} is not supported or valid" + exit 1 + end + end + + + # this is the main entry point that retrospec will use to make magic happen + # this is called after everything has been initialized + def run # the safe_create_module_files will render every file that ends with .retrospec.erb # under the templates/module_files folder in your gem and copy them to the destination. safe_create_module_files(template_dir, module_path, context) # Should you need to change the file name of the copied file you will have to move # the file outside of the module_files directory and # render it using: safe_create_template_file(file_path, template, context) - end + end - # the template directory located inside the your retrospec plugin gem - # you should not have to modify this unless you move the templates directory - # if this directory does not exist please create a directory templates/module_files - def template_dir - @template_dir ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates')) - end + # the template directory located inside the your retrospec plugin gem + # you should not have to modify this unless you move the templates directory + # if this directory does not exist please create a directory templates/module_files + def template_dir + @template_dir ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates')) + end end end end end \ No newline at end of file