Class: OptionsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptest-publisher/options_parser.rb

Class Method Summary collapse

Class Method Details

.all_optionsObject



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/hiptest-publisher/options_parser.rb', line 223

def self.all_options
  [
    Option.new('t', 'token=TOKEN', nil, String, I18n.t('options.token'), :token),
    Option.new('l', 'language=LANG', 'ruby', String, I18n.t('options.language'), :language),
    Option.new('f', 'framework=FRAMEWORK', '', String, I18n.t('options.framework'), :framework),
    Option.new('o', 'output-directory=PATH', '.', String, I18n.t('options.output_directory'), :output_directory),
    Option.new(nil, 'filename-pattern=PATTERN', nil, String, I18n.t('options.filename_pattern'), :filename_pattern),
    Option.new('c', 'config-file=PATH', nil, String, I18n.t('options.config'), :config),
    Option.new(nil, 'overriden-templates=PATH', '', String, I18n.t('options.overriden_templates'), :overriden_templates),
    Option.new(nil, 'overriden-language-configs=PATH', '', String, I18n.t('options.overriden_language_configs'), :overriden_language_configs),
    Option.new(nil, 'test-run-id=ID', '', String, I18n.t('options.test_run_id'), :test_run_id),
    Option.new(nil, 'test-run-name=NAME', '', String, I18n.t('options.test_run_name'), :test_run_name),
    Option.new(nil, 'only=CATEGORIES', nil, String, I18n.t('options.only'), :only),
    Option.new(nil, 'without=CATEGORIES', nil, String, I18n.t('options.without'), :without),
    Option.new('x', 'xml-file=PROJECT_XML', nil, String, I18n.t('options.xml_file'), :xml_file),
    Option.new(nil, 'cache-dir=PATH', self.default_cache_directory, String, I18n.t('options.cache_dir'), :cache_dir),
    Option.new(nil, 'cache-duration=DURATION', 60, Integer, I18n.t('options.cache_duration'), :cache_duration),
    Option.new(nil, 'tests-only', false, nil, I18n.t('options.tests_only'), :tests_only),
    Option.new(nil, 'actionwords-only', false, nil, I18n.t('options.actionwords_only'), :actionwords_only),
    Option.new(nil, 'actionwords-signature', false, nil, I18n.t('options.actionwords_signature'), :actionwords_signature),
    Option.new(nil, 'show-actionwords-diff', false, nil, I18n.t('options.actionwords_diff'), :actionwords_diff),
    Option.new(nil, 'show-actionwords-diff-as-json', false, nil, I18n.t('options.actionwords_diff_json'), :actionwords_diff_json),
    Option.new(nil, 'show-actionwords-deleted', false, nil, I18n.t('options.aw_deleted'), :aw_deleted),
    Option.new(nil, 'show-actionwords-created', false, nil, I18n.t('options.aw_created'), :aw_created),
    Option.new(nil, 'show-actionwords-renamed', false, nil, I18n.t('options.aw_renamed'), :aw_renamed),
    Option.new(nil, 'show-actionwords-signature-changed', false, nil, I18n.t('options.aw_signature_changed'), :aw_signature_changed),
    Option.new(nil, 'show-actionwords-definition-changed', false, nil, I18n.t('options.aw_definition_changed'), :aw_definition_changed),
    Option.new(nil, 'library-name=LIBRARY_NAME', nil, String, I18n.t('options.library_name'), :library_name),
    Option.new(nil, 'with-folders', false, nil, I18n.t('options.with_folders'), :with_folders),
    Option.new(nil, 'empty-folders', false, nil, I18n.t('options.empty_folders'), :empty_folders),
    Option.new(nil, 'split-scenarios', false, nil, I18n.t('options.split_scenarios'), :split_scenarios),
    Option.new(nil, 'leafless-export', false, nil, I18n.t('options.leafless_export'), :leafless_export),
    Option.new('s', 'site=SITE', 'https://studio.cucumber.io', String, I18n.t('options.site'), :site),
    Option.new(nil, 'http-proxy=PROXY_URL', nil, String, I18n.t('options.http_proxy'), :http_proxy),
    Option.new('p', 'push=FILE.TAP', '', String, I18n.t('options.push'), :push),
    Option.new(nil, 'global-failure-on-missing-reports', false, nil, I18n.t('options.global_failure_on_missing_reports'), :global_failure_on_missing_reports),
    Option.new(nil, 'push-format=tap', 'tap', String, I18n.t('options.push_format'), :push_format),
    Option.new(nil, 'execution-environment=NAME', '', String, I18n.t('options.execution_environment'), :execution_environment),
    Option.new(nil, 'build-id=ID', '', String, I18n.t('options.build_id'), :build_id),
    Option.new(nil, 'build-name=NAME', '', String, I18n.t('options.build_name'), :build_name),
    Option.new(nil, 'sort=[id,order,alpha]', 'order', String, I18n.t('options.sort'), :sort),
    Option.new(nil, '[no-]uids', false, nil, I18n.t('options.uids'), :uids),
    Option.new(nil, '[no-]parent-folder-tags', true, nil, I18n.t('options.parent_folder_tags'), :parent_folder_tags),
    Option.new(nil, 'parameter-delimiter=DELIMITER', '"', EmptiableString, I18n.t('options.parameter_delimiter'), :parameter_delimiter),
    Option.new(nil, 'with-dataset-names', false, nil, I18n.t('options.with_dataset_names'), :with_dataset_names),
    Option.new(nil, 'keep-filenames', false, nil, I18n.t('options.keep_filenames'), :keep_filenames),
    Option.new(nil, 'keep-foldernames', false, nil, I18n.t('options.keep_foldernames'), :keep_foldernames),
    Option.new(nil, 'filter-on-scenario-ids=IDS', '', String, I18n.t('options.filter_on_scenario_ids'), :filter_on_scenario_ids),
    Option.new(nil, 'filter-on-folder-ids=IDS', '', String, I18n.t('options.filter_on_folder_ids'), :filter_on_folder_ids),
    Option.new(nil, 'filter-on-scenario-name=NAME', '', String, I18n.t('options.filter_on_scenario_name'), :filter_on_scenario_name),
    Option.new(nil, 'filter-on-folder-name=NAME', '', String, I18n.t('options.filter_on_folder_name'), :filter_on_folder_name),
    Option.new(nil, 'filter-on-tags=TAGS', '', String, I18n.t('options.filter_on_tags'), :filter_on_tags),
    Option.new(nil, 'filter-on-status=STATUS', '', String, I18n.t('options.filter_on_status'), :filter_on_status),
    Option.new(nil, 'not-recursive', false, nil, I18n.t('options.not_recursive'), :not_recursive),
    Option.new(nil, 'meta=META', '', String, I18n.t('options.meta'), :meta),
    Option.new(nil, 'check-version', false, nil, I18n.t('options.check_version'), :check_version),
    Option.new(nil, 'force', false, nil, I18n.t('options.force_overwrite'), :force_overwrite),
    Option.new(nil, '[no-]color', nil, nil, I18n.t('options.color'), :color),
    Option.new('v', 'verbose', false, nil, I18n.t('options.verbose'), :verbose),
    Option.new(nil, 'indentation=INDENTATION', nil, EmptiableString, I18n.t('options.indentation'), :indent)
  ]
end

.default_cache_directoryObject



286
287
288
289
290
291
292
293
294
# File 'lib/hiptest-publisher/options_parser.rb', line 286

def self.default_cache_directory
  home_dir =  begin
                Dir.home
              rescue
                '.'
              end

  File.join(home_dir, '.hiptest-publisher', 'cache')
end

.languagesObject



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/hiptest-publisher/options_parser.rb', line 200

def self.languages
  # First framework is default framework

  {
    'Ruby' => ['Rspec', 'MiniTest'],
    'Cucumber' => ['Ruby', 'Java', 'Javascript', 'Groovy', 'TypeScript'],
    'Cucumber_Legacy' => ['Java', 'Groovy', 'TypeScript'],
    'Java' => ['JUnit', 'Test NG', 'Espresso'],
    'Python' => ['Unittest'],
    'Robot Framework' => [''],
    'Selenium IDE' => [''],
    'Javascript' => ['qUnit', 'Jasmine', 'Mocha', 'Protractor', 'CodeceptJS'],
    'CSharp' => ['NUnit'],
    'PHP' => ['PHPUnit'],
    'SpecFlow' => [''],
    'Behave' => [''],
    'Behat' => [''],
    'Groovy' => ['Spock'],
    'JBehave' => [''],
    'Swift' => ['XCTest']
  }
end

.make_language_option(lang, framework = '') ⇒ Object



327
328
329
330
331
332
# File 'lib/hiptest-publisher/options_parser.rb', line 327

def self.make_language_option(lang, framework = '')
  lang_opt = "--language=#{lang.downcase.gsub(' ', '')}"
  framework_opt = "--framework=#{framework.downcase.gsub(' ', '')}"

  framework.empty? ? lang_opt : "#{lang_opt} #{framework_opt}"
end

.parse(args, reporter) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/hiptest-publisher/options_parser.rb', line 296

def self.parse(args, reporter)
  options = CliOptions.new
  opt_parser = OptionParser.new do |opts|
    opts.version = hiptest_publisher_version if hiptest_publisher_version
    opts.banner = I18n.t('help.header')
    opts.separator I18n.t("help.description")
    opts.accept(EmptiableString, /.*/m) { |s,*| s }

    all_options.each {|o| o.register(opts, options)}

    opts.on("-H", "--languages-help", I18n.t('options.languages_help')) do
      self.show_languages
      exit
    end

    opts.on_tail("-h", "--help", I18n.t('options.help')) do
      puts opts
      exit
    end
  end

  args << "--help" if args.empty?
  opt_parser.parse!(args)
  reporter.add_listener(ConsoleFormatter.new(options.verbose, color: options.color))
  FileConfigParser.update_options(options, reporter)

  reporter.show_options(options.marshal_dump)
  options.normalize!(reporter)
  options
end

.show_languagesObject



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/hiptest-publisher/options_parser.rb', line 334

def self.show_languages
  puts I18n.t('help.languages.supported_languages')
  languages.each do |language, frameworks|
    puts "#{language}:"
    if frameworks.empty?
      puts I18n.t('help.languages.no_framework_available', language: make_language_option(language, ''))
    else
      frameworks.each_with_index do |fw, index|
        if index == 0
          puts " - #{fw} [#{I18n.t(:default)}] #{make_language_option(language, '')}"
        else
          puts " - #{fw} #{make_language_option(language, fw)}"
        end
      end
    end
  end
end