Class: Benry::CmdApp::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/benry/cmdapp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, global_option_schema = nil, app_help_builder = nil, action_help_builder = nil, _registry: REGISTRY) ⇒ Application

Returns a new instance of Application.



1748
1749
1750
1751
1752
1753
1754
# File 'lib/benry/cmdapp.rb', line 1748

def initialize(config, global_option_schema=nil, app_help_builder=nil, action_help_builder=nil, _registry: REGISTRY)
  @config        = config
  @option_schema = global_option_schema || GLOBAL_OPTION_SCHEMA_CLASS.new(config)
  @_registry     = _registry
  @app_help_builder    = app_help_builder
  @action_help_builder = action_help_builder
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



1756
1757
1758
# File 'lib/benry/cmdapp.rb', line 1756

def config
  @config
end

#option_schemaObject (readonly)

Returns the value of attribute option_schema.



1756
1757
1758
# File 'lib/benry/cmdapp.rb', line 1756

def option_schema
  @option_schema
end

Instance Method Details

#inspectObject



1758
1759
1760
# File 'lib/benry/cmdapp.rb', line 1758

def inspect()
  return super.split().first() + ">"
end

#main(argv = ARGV) ⇒ Object



1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
# File 'lib/benry/cmdapp.rb', line 1762

def main(argv=ARGV)
  #; [!65e9n] returns `0` as status code.
  status_code = run(*argv)
  return status_code
#rescue Benry::CmdOpt::OptionError => exc
#  raise if $DEBUG_MODE
#  print_error(exc)
#  return 1
#; [!bkbb4] when error raised...
rescue StandardError => exc
  #; [!k4qov] not catch error if debug mode is enabled.
  raise if $DEBUG_MODE
  #; [!lhlff] catches error if BaseError raised or `should_rescue?()` returns true.
  raise if ! should_rescue?(exc)
  #; [!35x5p] prints error into stderr.
  print_error(exc)
  #; [!z39bh] prints backtrace unless error is a CommandError.
  print_backtrace(exc) if ! exc.is_a?(BaseError) || exc.should_report_backtrace?()
  #; [!dzept] returns `1` as status code.
  return 1
end

#render_help_message(action = nil, all: false) ⇒ Object



1824
1825
1826
1827
1828
1829
1830
# File 'lib/benry/cmdapp.rb', line 1824

def render_help_message(action=nil, all: false)
  #; [!2oax5] returns action help message if action name is specified.
  #; [!d6veb] returns application help message if action name is not specified.
  #; [!tf2wp] includes hidden actions and options into help message if `all: true` passed.
  return render_action_help(action, all: all) if action
  return render_application_help(all: all)
end

#run(*args) ⇒ Object



1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
# File 'lib/benry/cmdapp.rb', line 1784

def run(*args)
  #; [!etbbc] calls setup method at beginning of this method.
  setup()
  #; [!hguvb] handles global options.
  global_opts = parse_global_options(args)  # raises OptionError
  toggle_global_options(global_opts)
  status_code = handle_global_options(global_opts, args)
  return status_code if status_code
  return handle_action(args, global_opts)
ensure
  #; [!pf1d2] calls teardown method at end of this method.
  teardown()
end