summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-12-06 13:16:39 +0200
committerPaul Buetow <paul@buetow.org>2024-12-06 13:16:39 +0200
commit9abea6c57e018f6033dfa8ffc6cdcdfc86ece969 (patch)
treee1bf81620f326e69a2be904a9973b61b9f578173
parentdbc25d5e39625045536dd5ab502babaf6993ed6b (diff)
fix options
-rw-r--r--Rakefile8
-rw-r--r--rcm/only_when.rb (renamed from rcm/conditions.rb)10
-rw-r--r--rcm/options.rb11
-rw-r--r--rcm/rcm.rb4
4 files changed, 15 insertions, 18 deletions
diff --git a/Rakefile b/Rakefile
index f41f084..5b2ec0e 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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)
diff --git a/rcm/rcm.rb b/rcm/rcm.rb
index 5c2e71e..3724a88 100644
--- a/rcm/rcm.rb
+++ b/rcm/rcm.rb
@@ -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!