lib/aigu/cli.rb in aigu-0.3.1 vs lib/aigu/cli.rb in aigu-0.4

- old
+ new

@@ -8,11 +8,11 @@ @options = parse_options_from_yaml(@options) @options = parse_options_from_arguments(@options) end def run - service_name = "#{@command}er".capitalize + service_name = "#{@command}er".split('_').map(&:capitalize).join begin service_class = Aigu.const_get(service_name) rescue NameError puts "The Aigu::#{service_name} service doesn’t exist. Nice try." @@ -26,26 +26,22 @@ protected def parse_options_from_yaml(options) file = File.join(Dir.pwd, '.aigu.yml') - if File.exists?(file) + if File.exist?(file) # Load YAML content content = YAML.load_file(file) - # Symbolize keys - content = content.reduce({}) do |memo, (key, value)| - memo.merge! key.to_sym => value - end - - # Merge with existing options - options = options.merge(content) + # Symbolize keys and merge with existing options + options = options.merge(content.symbolize_keys) end options end + # rubocop:disable Metrics/MethodLength def parse_options_from_arguments(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| @@ -70,16 +66,25 @@ opts.on('--ignore=', 'Patterns to ignore, separated by commas') do |ignore| options[:ignore] = ignore.split(',') end + opts.on('--accent-api-key=', 'Accent API key') do |key| + options[:'accent-api-key'] = key + end + + opts.on('--accent-url=', 'Accent URL (ex: http://accent.mirego.com)') do |url| + options[:'accent-url'] = url + end + opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end.parse! @argv options end + # rubocop:enable Metrics/MethodLength end end