diff options
| -rw-r--r-- | Rakefile | 8 | ||||
| -rw-r--r-- | rcm/only_when.rb (renamed from rcm/conditions.rb) | 10 | ||||
| -rw-r--r-- | rcm/options.rb | 11 | ||||
| -rw-r--r-- | rcm/rcm.rb | 4 |
4 files changed, 15 insertions, 18 deletions
@@ -1,12 +1,10 @@ require_relative 'rcm/rcm' desc 'Set up wireguard mesh' -task :wireguard do |t| - rcm do +task :wireguard do + make_it_so do p option :verbose - conditions do - hostname is :earth - end + only_when { hostname is :earth } file '/etc/wg/wg0.conf' do content 'the content' diff --git a/rcm/conditions.rb b/rcm/only_when.rb index f90c74c..2700bee 100644 --- a/rcm/conditions.rb +++ b/rcm/only_when.rb @@ -1,6 +1,6 @@ module RCM - # Conditions (e.g. run on host foo) - class Conditions + # OnlyWhen (e.g. run on host foo) + class OnlyWhen require 'socket' def initialize @@ -26,10 +26,10 @@ module RCM end end - # Add conditions "keyword" to the DSL + # Add 'only_when' to DSL class RCM - def conditions(&block) - conds = Conditions.new + def only_when(&block) + conds = OnlyWhen.new conds.instance_eval(&block) @conds_met = conds.met? end diff --git a/rcm/options.rb b/rcm/options.rb index ab3e25d..de54888 100644 --- a/rcm/options.rb +++ b/rcm/options.rb @@ -7,13 +7,12 @@ module RCM verbose: false } - parser = OptionParser.new do |opts| - opts.banner = 'Usage: rake [target] -- [options]' - opts.on('-v', '--[no-]verbose', 'run verbosely') { |v| @@options[:verbose] = v } - end + after_double_dash = ARGV.slice_before('--').to_a.last.drop(1) - parser.order!(ARGV) {} - parser.parse! + OptionParser.new do |opts| + opts.banner = 'Usage: rake [task] -- [options]' + opts.on('-v', '--[no-]verbose', 'run verbosely') { |v| @@options[:verbose] = v } + end.parse!(after_double_dash) def option(key) raise "No such option: #{key}" unless @@options.key?(key) @@ -1,5 +1,5 @@ require_relative 'options' -require_relative 'conditions' +require_relative 'only_when' require_relative 'file' # Ruby Configiration Management system @@ -23,7 +23,7 @@ module RCM end end -def rcm(&block) +def make_it_so(&block) rcm = RCM::RCM.new rcm.instance_eval(&block) rcm.do! |
