summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-12-06 13:00:42 +0200
committerPaul Buetow <paul@buetow.org>2024-12-06 13:00:42 +0200
commitdbc25d5e39625045536dd5ab502babaf6993ed6b (patch)
tree65c2b91b04abbcfb6bc3417b34b611ff1b8dc884
parent56f196bf91dda5178f7e2b8d39114c4c9197d58e (diff)
add options parser
-rw-r--r--Rakefile4
-rw-r--r--rcm/options.rb24
-rw-r--r--rcm/rcm.rb5
3 files changed, 31 insertions, 2 deletions
diff --git a/Rakefile b/Rakefile
index 1a7ea43..f41f084 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,7 +1,9 @@
require_relative 'rcm/rcm'
-task :default do |t|
+desc 'Set up wireguard mesh'
+task :wireguard do |t|
rcm do
+ p option :verbose
conditions do
hostname is :earth
end
diff --git a/rcm/options.rb b/rcm/options.rb
new file mode 100644
index 0000000..ab3e25d
--- /dev/null
+++ b/rcm/options.rb
@@ -0,0 +1,24 @@
+require 'optparse'
+
+module RCM
+ # Command line options
+ module Options
+ @@options = {
+ 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
+
+ parser.order!(ARGV) {}
+ parser.parse!
+
+ def option(key)
+ raise "No such option: #{key}" unless @@options.key?(key)
+
+ @@options[key]
+ end
+ end
+end
diff --git a/rcm/rcm.rb b/rcm/rcm.rb
index 6c69d7b..5c2e71e 100644
--- a/rcm/rcm.rb
+++ b/rcm/rcm.rb
@@ -1,10 +1,13 @@
+require_relative 'options'
require_relative 'conditions'
require_relative 'file'
-
+
# Ruby Configiration Management system
module RCM
# Here all starts
class RCM
+ include Options
+
def initialize
@objs = []
@conds_met = true