lib/aigu/cli.rb in aigu-0.2.1 vs lib/aigu/cli.rb in aigu-0.3

- old
+ new

@@ -2,11 +2,13 @@ class CLI def initialize(env, argv) @env = env @command = argv.first =~ /^[^-]/ ? argv.shift : nil @argv = argv - parse_options + @options = {} + @options = parse_options_from_yaml(@options) + @options = parse_options_from_arguments(@options) end def run service_name = "#{@command}er".capitalize @@ -19,40 +21,65 @@ service_object = service_class.new(@options) service_object.process! end - def parse_options - @options = {} + protected + def parse_options_from_yaml(options) + file = File.join(Dir.pwd, '.aigu.yml') + + if File.exists?(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) + end + + options + end + + 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| - @options[:input_directory] = 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 + options[:output_directory] = directory end opts.on('--input-file=', 'The JSON file generated by Accent.') do |file| - @options[:input_file] = 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 + 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 + options[:locale] = locale end + opts.on('--ignore=', 'Patterns to ignore, separated by commas') do |ignore| + options[:ignore] = ignore.split(',') + end + opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end.parse! @argv + + options end end end