Class: Vocab::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/vocab/application.rb

Class Method Summary collapse

Class Method Details

.handle_commandObject

CLI



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/vocab/application.rb', line 16

def handle_command
  success = true
  options = OpenStruct.new
  parser = OptionParser.new

  parser.banner = 'Usage: vocab [-h] command [platform] [type] [path]'
  parser.on( '-h', '--help', 'Show this usage message' ) { options.help = true }
  parser.on( '-s', '--strict', 'Require matching order of interpolations' ) { options.strict = true }
  parser.separator ""
  parser.separator "    vocab init"
  parser.separator "    vocab extract rails"
  parser.separator "    vocab extract rails all"
  parser.separator "    vocab extract android"
  parser.separator "    vocab clean rails"
  parser.separator "    vocab convert rails xml2yml <infile>"
  parser.separator "    vocab convert rails yml2xml <infile>"
  parser.separator "    vocab merge rails [-s]"
  parser.separator "    vocab merge android"
  parser.separator "    vocab validate android"
  parser.separator "    vocab validate rails"
  parser.separator "    vocab interpolation rails <file> [-s]"
  parser.separator "    vocab interpolation android <file>"
  parser.separator ""

  commands = parser.parse( ARGV )
  options.command = commands[0]
  options.platform = commands[1]
  options.type = commands[2]
  options.path = commands[3]

  if( options.command == 'init' )
    Vocab::Settings.create
  elsif( options.command == 'clean' && options.platform == 'rails' )
    Cleaner::Rails.clean
  elsif( options.command == 'clean' && options.platform == 'android' )
    Cleaner::Android.clean
  elsif( options.command == 'convert' && options.platform == 'rails' )
    if options.type == 'xml2yml'
      Converter::Rails.convert_xml_to_yml( options.path )
    elsif options.type = 'yml2xml'
      Converter::Rails.convert_yml_to_xml( options.path )
    else
      puts parser.help
    end
  elsif( options.command == 'extract' && options.platform == 'rails' )
    if options.type == 'all'
      Extractor::Rails.extract_all
    else
      Extractor::Rails.extract
    end
  elsif( options.command == 'extract' && options.platform == 'android' )
    Extractor::Android.extract
  elsif( options.command == 'merge' && options.platform == 'rails' )
    Merger::Rails.new.merge( options.strict )
  elsif( options.command == 'merge' && options.platform == 'android' )
    Merger::Android.new.merge
  elsif( options.command == 'validate' && options.platform == 'android' )
    success = Validator::Android.new.validate
  elsif( options.command == 'validate' && options.platform == 'rails' )
    success = Validator::Rails.new.validate
  elsif( options.command == 'interpolation' && options.platform == 'rails' && !options.type.nil? )
      Vocab::Merger::Rails.new.check_all_interpolations( options.type, options.strict )
  elsif( options.command == 'interpolation' && options.platform == 'android' && !options.type.nil? )
    Vocab::Merger::Android.new.check_all_format_strings( options.type )
  else
    puts parser.help
  end
  
  return success
end

.runObject



8
9
10
# File 'lib/vocab/application.rb', line 8

def run
  return handle_command
end