Class: Argument
- Inherits:
-
Object
- Object
- Argument
- Defined in:
- lib/trail_marker/argument.rb
Overview
Parses command line argument. Avoids requiring a dependent gem, easy to add any parameters and tags To Add New Parameter:
=> Add new tag in @valid_parameters
=> Change HELP message to describe new parameter added
Constant Summary collapse
- USAGE =
"Usage: \n testrail_marker -r run_plan_name -p project_name -x /home/path_to/results_xml/dir \n"
- HELP =
" -h, Show HELP -p *, name of project (e.g. TestRail API Gem) (required parameter) -r or -t *, name of test run (-r) or test plan (-t) (required parameter) -m, milestone name (can be used when creating a test run) -s, test suite name (* required when creating a test run) -u, user (e.g. [email protected]) -pw, password or token (recommended) -url, URL of TestRail (e.g. https://yourcompany.testrail.io) -cf, create a configuration file -d, debug mode (set to false to suppresses most messages) -x or -f *, path (-x, Directory) or specific file (-f) for results to parse -com, comment to put on each test NOTES: Results must have TestRail test case numbers to match. See README file for more details. Create options are available by adding \'c\' to some arguments, ex. -cr would create a new test run."
- REQUIRED =
"\nMissing required parameter/s (until config file implemented): Ex: testrail_marker -p TestRail API Gem -r Regression Suite -x ./results/path -p, name of project (e.g. -p TestRail API Gem) -r or -t, name of test run or test plan (e.g. -r Regression Suite) -x or -f, path (Directory) or a specific file of results to parse (e.g. -f /home/path/results/rspec_results.xml)\n"
Instance Method Summary collapse
- #arg_exists?(tag) ⇒ Boolean
-
#get_arg_value(tag) ⇒ Object
Returns the argument parameter passed with the specified tag.
- #get_optional_arg(tag_arr) ⇒ Object
- #has_argument?(tag) ⇒ Boolean
-
#initialize(passed_arguments) ⇒ Argument
constructor
Constructor.
- #parse_args(arguments) ⇒ Object
- #print_arguments ⇒ Object
Constructor Details
#initialize(passed_arguments) ⇒ Argument
Constructor. Requires passing the parameters from the command line argument.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/trail_marker/argument.rb', line 37 def initialize(passed_arguments) @arg_passed = passed_arguments @valid_parameters = ['-p', '-m', '-r', '-h', '-u', '-pw', '-url', '-d', '-x', '-t', '-s', '-com', '-f'] @create_parameters = ['-cm', '-cr', '-ct'] @delete_parameters = ['-dm', '-dr', '-dt'] @runner_parameters = ['-cf'] @valid_parameters += @create_parameters @valid_parameters += @delete_parameters @valid_parameters += @runner_parameters @required_parameters = ['-p'] @requires_atleast_one = ['-r', '-t', '-cr', '-ct'] @requires_only_one = ['-x', '-f'] check_help(passed_arguments) initialize_holder() parse_args(passed_arguments) check_required_parameters(passed_arguments) print_arguments end |
Instance Method Details
#arg_exists?(tag) ⇒ Boolean
112 113 114 115 116 117 118 119 |
# File 'lib/trail_marker/argument.rb', line 112 def arg_exists?(tag) it_exists = false tagv = get_arg_value(tag) if ! tagv.nil? && tagv != "" it_exists = true end return it_exists end |
#get_arg_value(tag) ⇒ Object
Returns the argument parameter passed with the specified tag
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/trail_marker/argument.rb', line 82 def get_arg_value(tag) tag_value = nil if @valid_parameters.include?(tag) tag_hash = @holder.detect{|tag_data| tag_data[:tag] == tag} tag_value = tag_hash[:value] else puts "ERROR: Parameter #{tag} not recognized." end return tag_value end |
#get_optional_arg(tag_arr) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/trail_marker/argument.rb', line 93 def get_optional_arg(tag_arr) tag_value = nil tag_arr.each do |tag| if @valid_parameters.include?(tag) tag_hash = @holder.detect{|tag_data| tag_data[:tag] == tag} tag_value = tag_hash[:value] else puts "ERROR: Parameter #{tag} not recognized." end if tag_value == "" tag_value = nil end if ! tag_value.nil? break end end return tag_value end |
#has_argument?(tag) ⇒ Boolean
121 122 123 124 125 126 |
# File 'lib/trail_marker/argument.rb', line 121 def has_argument?(tag) if @arg_passed.include?(tag) return true end return false end |
#parse_args(arguments) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/trail_marker/argument.rb', line 66 def parse_args(arguments) par_index = [] puts "ARG: #{arguments}" @valid_parameters.each do |tag| arg_index = arguments.index(tag).nil? ? -1 : arguments.index(tag) par_index.push(arg_index) end @valid_parameters.each_with_index do |tag, x| tag_index = par_index[x] end_index = get_next_highest(tag_index, par_index) save_arg_to_holder(arguments, tag_index, end_index) end end |
#print_arguments ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/trail_marker/argument.rb', line 57 def print_arguments() puts "\nPassed Arguments:" @holder.each do |hold| if hold[:value] != "" puts " #{hold[:tag]} #{hold[:value]}" end end end |