Sha256: d4127dcac08dd0ec82335de7faf83aff1a79d7258394b34c6ba57232a401911a

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

# -*- encoding : utf-8 -*-

require File.expand_path('../options_factory', __FILE__)

class Phrase::Tool::Options
  def initialize(args, command="")
    @command = command
    # specify all possible arguments here
    @data = {
      default: {
        version: false,
        help: false
      },
      init: {
        secret: "",
        default_locale: "en",
        domain: "phrase",
        format: nil,
        locale_filename: nil,
        locale_directory: nil,
        target_directory: nil 
      },
      push: {
        tags: [],
        recursive: false,
        locale: nil
      },
      pull: {
        format: nil,
        target: nil
      }
    }
    options.parse!(args)
  end
  
  def get(name)
    return @data.fetch(command_name).fetch(name.to_sym)
  rescue => e
    $stderr.puts "Invalid or missing option \"#{name}\" for command \"#{command_name}\""
  end
  
private
  
  def options
    OptionsFactory.options_for(command_name, @data)
  end
  
  def command_name
    @command_name ||= (@command.present? and @data.has_key?(@command.to_sym)) ? @command.to_sym : :default
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
phrase-0.4.1 lib/phrase/tool/options.rb
phrase-0.4.0 lib/phrase/tool/options.rb
phrase-0.3.7 lib/phrase/tool/options.rb
phrase-0.3.6 lib/phrase/tool/options.rb
phrase-0.3.5 lib/phrase/tool/options.rb
phrase-0.3.4 lib/phrase/tool/options.rb
phrase-0.3.3 lib/phrase/tool/options.rb