class MyOptParser

Attributes

options[R]

Public Class Methods

new() click to toggle source
# File lib/org_lang_stats/my_opt_parser.rb, line 7
def initialize
    @options = { org: nil, debug: false, threads: 10, token: nil, percent: false }
    parse_options
    validate_options
end

Public Instance Methods

parse_options() click to toggle source
# File lib/org_lang_stats/my_opt_parser.rb, line 13
def parse_options

    opt_parser = OptionParser.new do |opts|
        opts.banner = "\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() click to toggle source
# File lib/org_lang_stats/my_opt_parser.rb, line 28
def validate_options
    abort '--org option missing' if @options[:org].nil?
    abort '--threads should be between 1 and 100' unless (1..100).cover?(@options[:threads])
end