Class: CliOptions

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

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ CliOptions

Returns a new instance of CliOptions.



93
94
95
96
97
98
99
# File 'lib/hiptest-publisher/options_parser.rb', line 93

def initialize(hash = nil)
  hash ||= {}
  hash[:language] ||= ""
  hash[:framework] ||= ""

  super(__cli_args: Set.new, __config_args: Set.new, **hash)
end

Instance Method Details

#actionwords_diff?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/hiptest-publisher/options_parser.rb', line 101

def actionwords_diff?
  actionwords_diff || actionwords_diff_json || aw_deleted || aw_created || aw_renamed || aw_signature_changed || aw_definition_changed
end

#command_line_used(exclude: []) ⇒ Object



133
134
135
136
137
138
139
140
# File 'lib/hiptest-publisher/options_parser.rb', line 133

def command_line_used(exclude: [])
  args = self.__cli_args.map do |key|
    next if exclude.include?(key)
    "--#{key.to_s.gsub('_', '-')}=#{self[key]}"
  end.compact

  "hiptest-publisher #{args.join(' ')}".strip
end

#groups_to_keepObject



129
130
131
# File 'lib/hiptest-publisher/options_parser.rb', line 129

def groups_to_keep
  only.split(",") if only
end

#language_frameworkObject



121
122
123
124
125
126
127
# File 'lib/hiptest-publisher/options_parser.rb', line 121

def language_framework
  if framework.empty?
    language
  else
    "#{language}-#{framework}"
  end
end

#normalize!(reporter = nil) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/hiptest-publisher/options_parser.rb', line 146

def normalize!(reporter = nil)
  self.uids = true if test_run? && uids_not_set_yet?
  self.no_uids = !uids # silent normalization
  modified_options = self.clone
  if actionwords_only
    modified_options.only = 'actionwords'
  elsif tests_only
    modified_options.only = 'tests'
  end

  if language.include?('-')
    modified_options.language, modified_options.framework = language.split("-", 2)
  elsif framework.empty?
    # pick first framework for the language
    _, frameworks = OptionsParser.languages.find do |language, frameworks|
      language.downcase.gsub(' ', '') == self.language.downcase.gsub(' ', '')
    end
    if frameworks
      modified_options.framework = frameworks.first.downcase
    end
  end

  if without
    begin
      available_groups = LanguageConfigParser.new(modified_options).filtered_group_names
      modified_options.only = (available_groups - without.split(',')).join(',')
    rescue ArgumentError
      # Ok, that will be handled by cli_options_checkers later on
    end
  end

  if self != modified_options
    delta = modified_options.table.select do |key, value|
      modified_options[key] != self[key]
    end
    marshal_load(modified_options.marshal_dump)
    if reporter
      reporter.show_options(delta, I18n.t("help.options.nomalized_options"))
    end
    return delta
  end
end

#push?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/hiptest-publisher/options_parser.rb', line 105

def push?
  option_present?(push)
end

#test_run?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/hiptest-publisher/options_parser.rb', line 117

def test_run?
  test_run_id? || test_run_name?
end

#test_run_id?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/hiptest-publisher/options_parser.rb', line 109

def test_run_id?
  option_present?(test_run_id)
end

#test_run_name?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/hiptest-publisher/options_parser.rb', line 113

def test_run_name?
  option_present?(test_run_name)
end

#uids_not_set_yet?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/hiptest-publisher/options_parser.rb', line 142

def uids_not_set_yet?
  !__cli_args.include?(:uids) && !__config_args.include?(:uids)
end