Sha256: f45f641952284a846a79a441e3bebe38b016f0069022db5a08ca6536b39c7bd2

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'optparse'
require 'maprename/app'

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("-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
      Maprename::App.new(config_file).run!(@options[:dry])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
maprename-0.1.0 lib/maprename/cli.rb