Class: OptparseLite::OptSpec
- Inherits:
-
Struct
- Object
- Struct
- OptparseLite::OptSpec
- Extended by:
- Lingual
- Defined in:
- lib/optparse-lite.rb
Instance Attribute Summary collapse
-
#accessor ⇒ Object
Returns the value of attribute accessor.
-
#arg_name ⇒ Object
Returns the value of attribute arg_name.
-
#default ⇒ Object
Returns the value of attribute default.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#long ⇒ Object
Returns the value of attribute long.
-
#names ⇒ Object
Returns the value of attribute names.
-
#noable ⇒ Object
Returns the value of attribute noable.
-
#optional ⇒ Object
(also: #optional?)
Returns the value of attribute optional.
-
#required ⇒ Object
(also: #required?)
Returns the value of attribute required.
-
#short ⇒ Object
Returns the value of attribute short.
-
#takes_argument ⇒ Object
(also: #takes_argument?)
Returns the value of attribute takes_argument.
Class Method Summary collapse
Instance Method Summary collapse
-
#cannonical_name ⇒ Object
class << self.
- #doc_sexp ⇒ Object
- #has_default? ⇒ Boolean
- #normalized_key ⇒ Object
- #syntax_tokens ⇒ Object
Methods included from Lingual
Instance Attribute Details
#accessor ⇒ Object
Returns the value of attribute accessor
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def accessor @accessor end |
#arg_name ⇒ Object
Returns the value of attribute arg_name
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def arg_name @arg_name end |
#default ⇒ Object
Returns the value of attribute default
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def default @default end |
#desc ⇒ Object
Returns the value of attribute desc
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def desc @desc end |
#long ⇒ Object
Returns the value of attribute long
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def long @long end |
#names ⇒ Object
Returns the value of attribute names
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def names @names end |
#noable ⇒ Object
Returns the value of attribute noable
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def noable @noable end |
#optional ⇒ Object Also known as: optional?
Returns the value of attribute optional
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def optional @optional end |
#required ⇒ Object Also known as: required?
Returns the value of attribute required
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def required @required end |
#short ⇒ Object
Returns the value of attribute short
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def short @short end |
#takes_argument ⇒ Object Also known as: takes_argument?
Returns the value of attribute takes_argument
866 867 868 |
# File 'lib/optparse-lite.rb', line 866 def takes_argument @takes_argument end |
Class Method Details
.parse(str) ⇒ Object
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 |
# File 'lib/optparse-lite.rb', line 886 def parse str names, reqs, opts, short, long, noable, caps = [],[],[],[],[], nil,nil str.split(/, */).each do |syn| failed(str.inspect) unless caps = @short_long.parse(syn) names.push(caps.short || caps.long) long.push "--#{caps.long}" if caps.long short.push "-#{caps.short}" if caps.short if caps.no failed("i dunno can u say no multiple times?") if noable noable = caps.no this = "#{caps.no}#{caps.long}" long.push "--#{this}" names.push this end if caps = @param.parse(syn) (caps.required ? reqs : opts).push(caps.required || caps.optional) end failed("don't know how to parse: #{syn.inspect}") unless syn.empty? end failed("can't have both required and optional arguments: "<< str.inspect) if reqs.any? && opts.any? arg_names = opts | reqs failed("let's not take arguments with no- style opts") if noable && arg_names.any? failed("spell the argument the same way each time: "<< oxford_comma(arg_names)) if arg_names.length > 1 new(names, opts.any? || reqs.any?, reqs.any?, opts.any?, arg_names.first, short, long, noable) end |
Instance Method Details
#cannonical_name ⇒ Object
class << self
920 921 922 |
# File 'lib/optparse-lite.rb', line 920 def cannonical_name syntax_tokens.last end |
#doc_sexp ⇒ Object
923 924 925 |
# File 'lib/optparse-lite.rb', line 923 def doc_sexp [[:opt, syntax_tokens*', ', * desc]] end |
#has_default? ⇒ Boolean
926 927 928 |
# File 'lib/optparse-lite.rb', line 926 def has_default? ! default.nil? # whatever. i don't care about nil defaults end |
#normalized_key ⇒ Object
929 930 931 |
# File 'lib/optparse-lite.rb', line 929 def normalized_key accessor ? accessor.to_sym : names.last.to_sym end |
#syntax_tokens ⇒ Object
932 933 934 935 936 937 938 939 940 |
# File 'lib/optparse-lite.rb', line 932 def syntax_tokens if noable ["--[#{noable}]#{names.first}"] else these = long + short these[these.length-1] = "#{these.last}#{arg_name}" these end end |