#!/usr/bin/env ruby # == Imports ================================================================ require 'fileutils' require 'optparse' require_relative '../lib/configature' # == Main =================================================================== options = { verbose: false, quiet: false, config_dir: Configature.config_dir } program = OptionParser.new do |opts| opts.banner = "Usage: config [options]" opts.on('-q', '--quiet', 'Run quietly with no output') do options[:quiet] = true end opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v| options[:verbose] = v end opts.on('-d', '--config-dir DIR', 'Configuration directory target') do |dir| options[:config_dir] = dir end end args = program.parse! if (options[:verbose]) puts 'Checking configuration directory %s' % options[:config_dir] end if (options[:quiet]) $stdout = StringIO.new end case (arg = args.first) when 'clean' Configature.configable_examples(options[:config_dir]) do |source, target| if (File.exist?(target)) print "* %s: " % File.basename(target) File.unlink(target) puts "removed" end end when nil Configature.configable_examples(options[:config_dir]) do |source, target| if (File.exist?(target)) if (File.read(target).match(/__[A-Z\_]+__/)) puts "* %s: present (requires configuration)" % File.basename(target) else puts "* %s: present" % File.basename(target) end else FileUtils.copy(source, target) if (File.read(target).match(/__[A-Z\_]+__/)) puts "* %s: created (requires configuration)" % File.basename(target) else puts "* %s: created" % File.basename(target) end end end else $stderr.puts("Unknown command #{arg.inspect}") exit(-1) end