Class: ALib::ConfigurableMain

Inherits:
AbstractMain show all
Defined in:
lib/alib-0.5.1/main.rb

Constant Summary

Constants included from AbstractMain::Constants

AbstractMain::Constants::EXIT_FAILURE, AbstractMain::Constants::EXIT_OK, AbstractMain::Constants::EXIT_PSEUDO_SUCCESS, AbstractMain::Constants::EXIT_SUCCESS

Constants included from Logging

Logging::DIV0, Logging::DIV1, Logging::DIV2, Logging::DIV3, Logging::EOL, Logging::SEC0, Logging::SEC1, Logging::SEC2, Logging::SEC3

Constants included from ALib

AUTOLOAD, BSearch, Configfile, Find, LIBDIR, Listfile, OrderedAutoHash, SINGLETON_CLASS, VERSION

Instance Attribute Summary

Attributes inherited from AbstractMain

#argv, #cmdline, #console, #env, #listoptions, #logdev, #logger, #op, #options, #program, #verbosity

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractMain

#__initialize__, argument, #argument, #arguments, arguments, #argv_plus_stdin, class_attributes, default, #defaults, defaults, #die, #exit_failure, exit_failure, #exit_ok, exit_ok, #exit_pseudo_success, exit_pseudo_success, #exit_status, #exit_success, exit_success, get_param, indent_block, inherited, #init_logging, #initialize, instance_attributes, #invalid_option, #klass, #logcatch, #main, main, new, option, #option, optional_argument, #optional_arguments, optional_arguments, options, #options?, param, #param, #param?, params, #params, parm, parms, #parse_argv, #parse_options, #post_init_logging, #post_main, #post_parse_options, #post_run, #pre_init_logging, #pre_main, #pre_parse_options, #pre_run, required_argument, #required_arguments, required_arguments, run, #run, #status_failure, status_failure, status_ok, #status_ok, status_pseudo_success, #status_pseudo_success, #status_success, status_success, stringlist, unindent_block, #usage, usage

Methods included from Logging

append_features

Constructor Details

This class inherits a constructor from ALib::AbstractMain

Class Method Details

.class_initializeObject

–{{{



938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
# File 'lib/alib-0.5.1/main.rb', line 938

def self.class_initialize
#--{{{
  super
  class_attribute :config_default_path
  class_attribute :config_search_path
  class_attribute :configfile

  config_default_path "#{ prognam }.conf"

  config_search_path %w(. ~ /usr/local/etc /usr/etc /etc)

  configfile Class::new(ALib::ConfigFile) #{ default = DATA; DATA.rewind; }

  optspec << [ '--config=path', 'valid path - specify config file (default nil)' ]
  optspec << [ '--template=[path]', 'valid path - generate a template config file in path (default stdout)' ]
#--}}}
end

Instance Method Details

#gen_template(template) ⇒ Object

–}}}



969
970
971
972
973
974
# File 'lib/alib-0.5.1/main.rb', line 969

def gen_template template
#--{{{
  klass::configfile::gen_template(template)
  self
#--}}}
end

#init_config(opts = @options) ⇒ Object

–}}}



980
981
982
983
984
985
986
987
988
989
990
991
# File 'lib/alib-0.5.1/main.rb', line 980

def init_config opts = @options
#--{{{
  conf = Util::getopt 'config', opts
  @config =
    if conf 
      klass::configfile::new(conf)
    else
      klass::configfile::any klass::config_default_path, klass::config_search_path
    end
  @config
#--}}}
end

#post_parse_argvObject

–}}}



975
976
977
978
979
# File 'lib/alib-0.5.1/main.rb', line 975

def post_parse_argv
#--{{{
  init_config
#--}}}
end

#pre_parse_argvObject



958
959
960
961
962
963
964
965
966
967
968
# File 'lib/alib-0.5.1/main.rb', line 958

def pre_parse_argv
#--{{{
  super
  if(@options.has_key?('template') or @argv.first =~ %r/template/i)
    @argv.shift if @argv.first =~ %r/template/i
    arg = @argv.first
    gen_template @options['template'] || @options['config'] || arg
    exit EXIT_SUCCESS
  end
#--}}}
end