Class: Optimist::IOOption

Inherits:
Option
  • Object
show all
Defined in:
lib/optimist_with_insert_blanks.rb

Overview

Option class for handling IO objects and URLs. Note that this will return the file-handle, not the file-name in the case of file-paths given to it.

Direct Known Subclasses

IOArrayOption

Instance Attribute Summary

Attributes inherited from Option

#default, #long, #multi_given, #name, #short

Instance Method Summary collapse

Methods inherited from Option

#array_default?, #callback, create, #desc, #description_with_default, #educate, #flag?, get_klass_from_default, get_type_from_disdef, handle_long_opt, handle_short_opt, #initialize, #multi, #multi_arg?, #opts, #opts=, register_alias, #required?, #short?, #single_arg?

Constructor Details

This class inherits a constructor from Optimist::Option

Instance Method Details

#parse(paramlist, _neg_given) ⇒ Object



956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
# File 'lib/optimist_with_insert_blanks.rb', line 956

def parse(paramlist, _neg_given)
  paramlist.map do |pg|
    pg.map do |param|
      if param =~ /^(stdin|-)$/i
        $stdin
      else
        require 'open-uri'
        begin
          open param
        rescue SystemCallError => e
          raise CommandlineError, "file or url for option '#{name}' cannot be opened: #{e.message}"
        end
      end
    end
  end
end

#type_formatObject



952
953
954
# File 'lib/optimist_with_insert_blanks.rb', line 952

def type_format
  '=<filename/uri>'
end