Class: SimpleScripting::Argv::ExitWithArgumentsHelpPrinting

Inherits:
Struct
  • Object
show all
Defined in:
lib/simple_scripting/argv.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



30
31
32
# File 'lib/simple_scripting/argv.rb', line 30

def args
  @args
end

#commands_stackObject

Returns the value of attribute commands_stack

Returns:

  • (Object)

    the current value of commands_stack



30
31
32
# File 'lib/simple_scripting/argv.rb', line 30

def commands_stack
  @commands_stack
end

#parser_opts_copyObject

Returns the value of attribute parser_opts_copy

Returns:

  • (Object)

    the current value of parser_opts_copy



30
31
32
# File 'lib/simple_scripting/argv.rb', line 30

def parser_opts_copy
  @parser_opts_copy
end

Instance Method Details



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/simple_scripting/argv.rb', line 31

def print_help(output, long_help)
  parser_opts_help = parser_opts_copy.to_s

  if commands_stack.size > 0
    parser_opts_help = parser_opts_help.sub!('[options]', commands_stack.join(' ') + ' [options]')
  end

  if args.size > 0
    args_display = args.map { |name, mandatory| mandatory ? "<#{ name }>" : "[<#{ name }>]" }.join(' ')
    parser_opts_help = parser_opts_help.sub!(/^(Usage: .*)/) { |text| "#{text} #{args_display}" }
  end

  output.puts parser_opts_help
  output.puts "", long_help if long_help
end