Sha256: b804a6a9f30af88b3708f8de6522a4e18178e2c70e634f9952380b6f3f0138b3

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

require 'optparse'
require 'maprename/app'

module Kernel
  def debug(msg)
    puts msg if $debug
  end
end

module Maprename
  class Cli
    def initialize
      @options = {}
      parse_options!
    end

    def parse_options!
      @raw_options = OptionParser.new do |opts|
        opts.banner = "Usage: maprename [options]"

        opts.on("-c", "--config CONFIG_FILE", "Specify config file, default to maprename.yml in current directory, see specification: https://github.com/lululau/maprename/blob/master/README.md") do |config|
          @options[:config] = config
        end

        opts.on("-d", "--dry", "dry run") do
          @options[:dry] = true
        end

        opts.on("-D", "--debug", "debug") do
          @options[:debug] = true
          $debug = true
        end

        opts.on("-h", "--help", "Prints this help") do
          puts opts
          exit
        end
      end

      @raw_options.parse!
    end

    def config_file
      @options[:config] || "maprename.yml"
    end

    def run!
      config = config_file
      unless File.exists?(config)
        puts @raw_options
        exit 1
      end
      debug "CLI Options: #{@options}"
      Maprename::App.new(config_file).run!(@options)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
maprename-0.1.5 lib/maprename/cli.rb
maprename-0.1.4 lib/maprename/cli.rb
maprename-0.1.3 lib/maprename/cli.rb
maprename-0.1.2 lib/maprename/cli.rb
maprename-0.1.1 lib/maprename/cli.rb