Class: AdLocalize::OptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/ad_localize/option_handler.rb

Class Method Summary collapse

Class Method Details

.parse!(options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ad_localize/option_handler.rb', line 3

def self.parse!(options)
  option_parser = OptionParser.new do |parser|
    parser.banner = "Usage: exe/ad_localize [options] file(s)"

    parser.on("-d", "--debug", TrueClass, "Run in debug mode")
    parser.on("-e", "--export-all-sheets", TrueClass,
              <<~DOC
                Export all sheets from spreadsheet specified by --drive-key option.
                \tBy default, generates one export directory per sheet (see -m|--merge-sheets option to merge them).
                \tAn GCLOUD_CLIENT_SECRET environment variable containing the client_secret.json content is needed.
    DOC
    )
    parser.on("-h", "--help", "Prints help") do
      puts parser
      exit
    end
    parser.on("-k", "--drive-key SPREADSHEET_ID", String, "Use google drive spreadsheets")
    parser.on("-m", "--merge-policy POLICY", String,
              <<~DOC
                Merge specified csv (or sheets from --export-all) instead of exporting each csv.
                \treplace: if a key is already defined, replace its value.
                \tkeep: if a key is already defined, keep the previous value.
    DOC
    )
    parser.on("-o", "--only PLATFORMS", Array, "PLATFORMS is a comma separated list. Only generate localisation files for the specified platforms. Supported platforms : #{Requests::ExportRequest::SUPPORTED_PLATFORMS.to_sentence}")
    parser.on("-s", "--sheets SHEET_IDS", Array, "SHEET_IDS is a comma separated list. Use a specific sheet id for Google Drive spreadsheets with several sheets")
    parser.on("-t", "--target-dir PATH", String, "Path to the target directory")
  end

  args = {}
  option_parser.parse!(options, into: args)
  args[:csv_paths] = options
  return args
end