Class: Schatz::Cli::Configuration
- Inherits:
-
Object
- Object
- Schatz::Cli::Configuration
- Defined in:
- lib/schatz/cli/configuration.rb
Instance Attribute Summary collapse
-
#opt ⇒ Object
Returns the value of attribute opt.
-
#options ⇒ Object
Returns the value of attribute options.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
- #full_file_name(file_name) ⇒ Object
-
#initialize(output = STDOUT, error = STDERR, options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #parse!(argv) ⇒ Object
- #read_config ⇒ Object
- #show_info ⇒ Object
Constructor Details
#initialize(output = STDOUT, error = STDERR, options = {}) ⇒ Configuration
Returns a new instance of Configuration.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/schatz/cli/configuration.rb', line 5 def initialize(output=STDOUT, error=STDERR,={}) @stdout = output @stderr = error = @opt = OptionParser.new @opt. = "Usage: schatz [file_name]" @opt.separator "Options:" @opt.on("-f", "--file [file]") {|file| [:file_name] = file} @opt.on("-h", "--help") {|ignore| [:help] = true} @opt.on("--po") {|ignore| [:proxy_only] = true} @opt.on("--do") {|ignore| [:direct_only] = true} @opt.on("-g", "--gcm [gcm]") {|gcm| [:gcm] = "gcm000000" +gcm} @opt.on("-p", "--prx [proxy]") {|proxy| [:proxies] = {1 => proxy}} end |
Instance Attribute Details
#opt ⇒ Object
Returns the value of attribute opt.
4 5 6 |
# File 'lib/schatz/cli/configuration.rb', line 4 def opt @opt end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/schatz/cli/configuration.rb', line 4 def end |
#stderr ⇒ Object
Returns the value of attribute stderr.
4 5 6 |
# File 'lib/schatz/cli/configuration.rb', line 4 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
4 5 6 |
# File 'lib/schatz/cli/configuration.rb', line 4 def stdout @stdout end |
Instance Method Details
#full_file_name(file_name) ⇒ Object
34 35 36 37 38 |
# File 'lib/schatz/cli/configuration.rb', line 34 def full_file_name(file_name) raise FileNotExistInCurrentDirectory until File.exist?(file_name) raise IncorrectFileFormat until file_name =~ /\.xlsx?/ || file_name =~ /\.html?/ || file_name =~ /\.txt?/ File.(file_name) end |
#parse!(argv) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/schatz/cli/configuration.rb', line 20 def parse!(argv) raise ArgumentError, "expected array of argv" unless argv.is_a?(Array) raise ArgumentError, "you should provide at least a name of the incr" if argv.empty? || argv.first=="-f" && argv.length==1 @opt.parse(argv) [:file_name] = full_file_name([:file_name]) if [:file_name] [:proxies] ||= read_config show_info end |
#read_config ⇒ Object
40 41 42 |
# File 'lib/schatz/cli/configuration.rb', line 40 def read_config YAML::load_file(File.(File.dirname(__FILE__)+"./../../../config/config.yml"))["proxies"] end |
#show_info ⇒ Object
29 30 31 32 |
# File 'lib/schatz/cli/configuration.rb', line 29 def show_info puts @opt if [:help] puts "GCM number is not provided so will check all links. If you want to test only those implemented after specified GCM please mention it".foreground(:yellow) unless [:gcm] end |