From dbc25d5e39625045536dd5ab502babaf6993ed6b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 6 Dec 2024 13:00:42 +0200 Subject: add options parser --- Rakefile | 4 +++- rcm/options.rb | 24 ++++++++++++++++++++++++ rcm/rcm.rb | 5 ++++- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 rcm/options.rb 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 -- cgit v1.2.3