diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d65167..e8efa49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Strainer CHANGELOG ================== +v3.0.3 +------ +- Add Thor and Rake tasks + v3.0.2 ------ - Output summary message diff --git a/Gemfile b/Gemfile index 3be9c3c..851fabc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,2 @@ -source "https://rubygems.org" +source 'https://rubygems.org' gemspec diff --git a/README.md b/README.md index 62ba328..3b927bf 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,29 @@ Strainer runs everything in an isolated sandbox, inside your Chef Repo. When inc # Strainerfile foodcritic: bundle exec foodcritic -I foodcritic/* -f any $SANDBOX/$COOKBOOK +Rake Task +--------- +Strainer includes a Rake task for convenience: + +```ruby +require 'strainer/rake_task' + +Strainer::RakeTask.new(:strainer) do |s| + s.except = [...] + s.strainerfile = 'MyStraienrfile' +end +``` + +Thor Task +--------- +Strainer includes a Thor task for convenience: + +```ruby +require 'strainer/thor' + +Strainer::Thor... +``` + Needs Your Help --------------- This is a list of features or problem *you* can help solve! Fork and submit a pull request to make Strain even better! diff --git a/lib/strainer/rake_task.rb b/lib/strainer/rake_task.rb new file mode 100644 index 0000000..d2edb26 --- /dev/null +++ b/lib/strainer/rake_task.rb @@ -0,0 +1,64 @@ +require 'rake' +require 'rake/tasklib' +require 'strainer/cli' + +module Strainer + # Run Strainer from rake + # + # @example + # desc "Run Strainer with Rake" + # Strainer::RakeTask.new(:strainer) do |strainer| + # strainer.except = ['kitchen'] + # end + class RakeTask < ::Rake::TaskLib + # @return [Symbol] + attr_accessor :name + + # @return [Hash] + attr_reader :options + + def initialize(task_name = nil) + @options = {} + @name = (task_name || :strainer).to_sym + + yield self if block_given? + + desc "Run Strainer" unless ::Rake.application.last_comment + task name, :cookbook_name do |t, args| + require 'strainer' + Strainer::Runner.new(Array(args[:cookbook_name]), options) + end + end + + Strainer::Cli.class_options.each do |option| + name = option.first + + define_method(name) do + options[name.to_sym] + end + + define_method("#{name}=") do |value| + options[name.to_sym] = value + end + end + + Striner::Cli.commands['test'].options.each do |key| + name = key.first + + define_method(name) do + options[name.to_sym] + end + + define_method("#{name}=") do |value| + options[name.to_sym] = value + end + end + + # Set the path to the strainerfile + # + # @param [String] file + def strainerfile=(file) + options[:strainerfile] = file + end + end +end diff --git a/lib/strainer/thor.rb b/lib/strainer/thor.rb new file mode 100644 index 0000000..00a41df --- /dev/null +++ b/lib/strainer/thor.rb @@ -0,0 +1,5 @@ +require 'strainer/cli' + +module Strainer + Thor = Cli +end