Class: MyOptParser
- Inherits:
-
Object
- Object
- MyOptParser
- Defined in:
- lib/org_lang_stats/my_opt_parser.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ MyOptParser
constructor
A new instance of MyOptParser.
- #parse_options ⇒ Object
- #validate_options ⇒ Object
Constructor Details
#initialize ⇒ MyOptParser
Returns a new instance of MyOptParser.
7 8 9 10 11 |
# File 'lib/org_lang_stats/my_opt_parser.rb', line 7 def initialize @options = { org: nil, debug: false, threads: 10, token: nil, percent: false } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/org_lang_stats/my_opt_parser.rb', line 5 def @options end |
Instance Method Details
#parse_options ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/org_lang_stats/my_opt_parser.rb', line 13 def opt_parser = OptionParser.new do |opts| opts. = "\nExample usage: org_lang_stats --org workable --threads 10 --token yourtokenhere --debug --percent\n\nOptions:" opts.on('--org string', String, 'Organization name as appeared on github (required)') { |org| @options[:org] = org } opts.on('--token string', String, 'Github Personal Access Token') { |token| @options[:token] = token } opts.on('--threads [1..100]', Integer, 'Adjusts the concurrency (default: 10)') { |threads| @options[:threads] = threads } opts.on('--debug', 'If enabled, adds debug messages to the output (will not produce valid json)') { @options[:debug] = true } opts.on('--percent', 'If enabled, converts absolute values (bytes) to percent values') { @options[:percent] = true } end opt_parser.parse! end |
#validate_options ⇒ Object
28 29 30 31 |
# File 'lib/org_lang_stats/my_opt_parser.rb', line 28 def abort '--org option missing' if @options[:org].nil? abort '--threads should be between 1 and 100' unless (1..100).cover?(@options[:threads]) end |