Sha256: 3456ac10f6896d6a6b76031a000406da2101752cb7ab50f76f60ee8999fcacbd

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

module Aigu
  class CLI
    def initialize(env, argv)
      @env = env
      @command = argv.first =~ /^[^-]/ ? argv.shift : nil
      @argv = argv
      parse_options
    end

    def run
      service_name = "#{@command}er".capitalize

      begin
        service_class = Aigu.const_get(service_name)
      rescue NameError
        puts "The Aigu::#{service_name} service doesn’t exist. Nice try."
        exit 0
      end

      service_object = service_class.new(@options)
      service_object.process!
    end

    def parse_options
      @options = {}

      OptionParser.new do |opts|
        opts.banner = 'Usage: aigu [options]'

        opts.on('--input-directory=', 'The directory in which the Rails YAML localization files are stored.') do |directory|
          @options[:input_directory] = directory
        end

        opts.on('--output-directory=', 'The directory in which the Rails YAML localization files will be generated.') do |directory|
          @options[:output_directory] = directory
        end

        opts.on('--input-file=', 'The JSON file generated by Accent.') do |file|
          @options[:input_file] = file
        end

        opts.on('--output-file=', 'The JSON file that will be generated for Accent.') do |file|
          @options[:output_file] = file
        end

        opts.on('--locale=', 'The locale to use. Files will be processed/generated using the "<file>.<locale>.yml" pattern.') do |locale|
          @options[:locale] = locale
        end

        opts.on_tail('-h', '--help', 'Show this message') do
          puts opts
          exit
        end

      end.parse! @argv
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aigu-0.2.1 lib/aigu/cli.rb
aigu-0.2 lib/aigu/cli.rb