Class: Optitron::Dsl::AbstractDsl

Inherits:
Object
  • Object
show all
Defined in:
lib/optitron/dsl.rb

Direct Known Subclasses

CmdParserDsl, RootParserDsl

Instance Method Summary collapse

Instance Method Details

#arg(name, description = nil, opts = nil) ⇒ Object

Raises:



42
43
44
45
46
47
48
# File 'lib/optitron/dsl.rb', line 42

def arg(name, description = nil, opts = nil)
  arg_option = Option::Arg.new(name, description, opts)                                                                         
  raise InvalidParser.new if @target.args.last and !@target.args.last.required? and arg_option.required? and arg_option.type != :greedy
  raise InvalidParser.new if @target.args.last and @target.args.last.type == :greedy
  @target.args << arg_option
  arg_option
end

#configure_with(&block) ⇒ Object



27
28
29
# File 'lib/optitron/dsl.rb', line 27

def configure_with(&block)
  instance_eval(&block)
end

#opt(name, description = nil, opts = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/optitron/dsl.rb', line 31

def opt(name, description = nil, opts = nil)
  opt_option = Option::Opt.new(name, description, opts)
  if opt_option.short_name
    short_opts[opt_option.short_name] = opt_option
  else
    unclaimed_opts << opt_option
  end
  @target.options << opt_option
  opt_option
end

#short_optsObject



50
51
52
# File 'lib/optitron/dsl.rb', line 50

def short_opts
  @root_dsl.short_opts
end

#unclaimed_optsObject



54
55
56
# File 'lib/optitron/dsl.rb', line 54

def unclaimed_opts
  @root_dsl.unclaimed_opts
end