diff options
| author | Paul Buetow <paul@buetow.org> | 2024-12-06 13:00:42 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-12-06 13:00:42 +0200 |
| commit | dbc25d5e39625045536dd5ab502babaf6993ed6b (patch) | |
| tree | 65c2b91b04abbcfb6bc3417b34b611ff1b8dc884 | |
| parent | 56f196bf91dda5178f7e2b8d39114c4c9197d58e (diff) | |
add options parser
| -rw-r--r-- | Rakefile | 4 | ||||
| -rw-r--r-- | rcm/options.rb | 24 | ||||
| -rw-r--r-- | rcm/rcm.rb | 5 |
3 files changed, 31 insertions, 2 deletions
@@ -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 @@ -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 |
