Class: OptionsParser

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

Class Method Summary collapse

Class Method Details

.all_optionsObject



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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
# File 'lib/hiptest-publisher/options_parser.rb', line 207

def self.all_options
  [
    Option.new('t', 'token=TOKEN', nil, String, "Secret token (available in your project settings)", :token),
    Option.new('l', 'language=LANG', 'ruby', String, "Target language", :language),
    Option.new('f', 'framework=FRAMEWORK', '', String, "Test framework to use", :framework),
    Option.new('o', 'output-directory=PATH', '.', String, "Output directory", :output_directory),
    Option.new(nil, 'filename-pattern=PATTERN', nil, String, "Filename pattern (containing %s)", :filename_pattern),
    Option.new('c', 'config-file=PATH', nil, String, "Configuration file", :config),
    Option.new(nil, 'overriden-templates=PATH', '', String, "Folder for overriden templates", :overriden_templates),
    Option.new(nil, 'test-run-id=ID', '', String, "Export data from a test run identified by its id", :test_run_id),
    Option.new(nil, 'test-run-name=NAME', '', String, "Export data from a test run identified by its name", :test_run_name),
    Option.new(nil, 'only=CATEGORIES', nil, String, "Restrict export to given file categories (--only=list to list them)", :only),
    Option.new(nil, 'without=CATEGORIES', nil, String, "Exclude file categories from import (--only=list to list them)", :without),
    Option.new('x', 'xml-file=PROJECT_XML', nil, String, "XML file to use instead of fetching it from Hiptest", :xml_file),
    Option.new(nil, 'tests-only', false, nil, "(deprecated) alias for --only=tests", :tests_only),
    Option.new(nil, 'actionwords-only', false, nil, "(deprecated) alias for --only=actionwords", :actionwords_only),
    Option.new(nil, 'actionwords-signature', false, nil, "Export actionwords signature", :actionwords_signature),
    Option.new(nil, 'show-actionwords-diff', false, nil, "Show actionwords diff since last update (summary)", :actionwords_diff),
    Option.new(nil, 'show-actionwords-diff-as-json', false, nil, "Show actionwords diff since last update (JSON output)", :actionwords_diff_json),
    Option.new(nil, 'show-actionwords-deleted', false, nil, "Output signature of deleted action words", :aw_deleted),
    Option.new(nil, 'show-actionwords-created', false, nil, "Output code for new action words", :aw_created),
    Option.new(nil, 'show-actionwords-renamed', false, nil, "Output signatures of renamed action words", :aw_renamed),
    Option.new(nil, 'show-actionwords-signature-changed', false, nil, "Output signatures of action words for which signature changed", :aw_signature_changed),
    Option.new(nil, 'show-actionwords-definition-changed', false, nil, "Output action words for which definition changed", :aw_definition_changed),
    Option.new(nil, 'library-name=LIBRARY_NAME', nil, String, "Use in conjunction with show-actionwords-*: show the diff for the specified library", :library_name),
    Option.new(nil, 'with-folders', false, nil, "Use folders hierarchy to export files in respective directories", :with_folders),
    Option.new(nil, 'empty-folders', false, nil, "Export empty folders", :empty_folders),
    Option.new(nil, 'split-scenarios', false, nil, "Export each scenario in a single file (except for Gherkin based languages)", :split_scenarios),
    Option.new(nil, 'leafless-export', false, nil, "Use only last level action word", :leafless_export),
    Option.new('s', 'site=SITE', 'https://app.hiptest.com', String, "Site to fetch from", :site),
    Option.new('p', 'push=FILE.TAP', '', String, "Push a results file to the server", :push),
    Option.new(nil, 'global-failure-on-missing-reports', false, nil, "When there is no results file to push, report a global failure", :global_failure_on_missing_reports),
    Option.new(nil, 'push-format=tap', 'tap', String, "Format of the test results (cucumber-json, junit, nunit, robot, tap)", :push_format),
    Option.new(nil, 'sort=[id,order,alpha]', 'order', String, "Sorting of tests in output: id will sort them by age, order will keep the same order than in hiptest (only with --with-folders option, will fallback to id otherwise), alpha will sort them by name", :sort),
    Option.new(nil, '[no-]uids', true, nil, 'Export UIDs (note: can be disabled only for Gherkin-based exports, may cause issue when pushing results back)', :uids),
    Option.new(nil, 'parameter-delimiter', '"', String, 'Parameter delimiter (for Gherkin based export only)', :parameter_delimiter),
    Option.new(nil, 'with-dataset-names', false, nil, 'Export dataset name when creating feature files (note: available only for Gherkin-based exports)', :with_dataset_names),
    Option.new(nil, 'keep-filenames', false, nil, "Keep the same name as in Hiptest for the test files (note: may cause encoding issues)", :keep_filenames),
    Option.new(nil, 'keep-foldernames', false, nil, "Keep the same name as in Hiptest for the folders (note: may cause encoding issues)", :keep_foldernames),
    Option.new(nil, 'filter-on-scenario-ids=IDS', '', String, "Filter on scenario ids (use commas to separate ids when fetching multiple scenarios)", :filter_on_scenario_ids),
    Option.new(nil, 'filter-on-folder-ids=IDS', '', String, "Filter on folder ids (use commas to separate ids when fetching multiple folders)", :filter_on_folder_ids),
    Option.new(nil, 'filter-on-scenario-name=NAME', '', String, "Filter on scenario name (only one name is accepted)", :filter_on_scenario_name),
    Option.new(nil, 'filter-on-folder-name=NAME', '', String, "Filter on folder name (only one name is accepted)", :filter_on_folder_name),
    Option.new(nil, 'filter-on-tags=TAGS', '', String, "Filter on scenarios and folder tags (use commas to separate tags when using multiple tags)", :filter_on_tags),
    Option.new(nil, 'filter-on-status=STATUS', '', String, "Filter on test status in last build (use in conjunction with a test run)", :filter_on_status),
    Option.new(nil, 'not-recursive', false, nil, "Used in conjunction with filter-on-folder-ids or filter-on-folder-name: only exports those folders, not their children", :not_recursive),
    Option.new(nil, 'check-version', false, nil, "Check if a new release of hiptest-publisher is available", :check_version),
    Option.new(nil, 'force', false, nil, "Force overwrite of existing files (do not apply to test files)", :force_overwrite),
    Option.new('v', 'verbose', false, nil, "Run verbosely", :verbose)
  ]
end

.languagesObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/hiptest-publisher/options_parser.rb', line 186

def self.languages
  # First framework is default framework

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

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



292
293
294
295
296
297
# File 'lib/hiptest-publisher/options_parser.rb', line 292

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



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
285
286
287
288
289
290
# File 'lib/hiptest-publisher/options_parser.rb', line 259

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 = "Usage: ruby publisher.rb [options]"
    opts.separator ""
    opts.separator "Exports tests from Hiptest for automation."
    opts.separator ""
    opts.separator "Specific options:"

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

    opts.on("-H", "--languages-help", "Show languages and framework options") do
      self.show_languages
      exit
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end

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

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

.show_languagesObject



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/hiptest-publisher/options_parser.rb', line 299

def self.show_languages
  puts "Supported languages:"
  languages.each do |language, frameworks|
    puts "#{language}:"
    if frameworks.empty?
      puts "  no framework option available #{make_language_option(language, '')}"
    else
      frameworks.each_with_index do |fw, index|
        if index == 0
          puts " - #{fw} [default] #{make_language_option(language, '')}"
        else
          puts " - #{fw} #{make_language_option(language, fw)}"
        end
      end
    end
  end
end