Class: ALib::MainModule::ConfigurableMain
- Inherits:
-
Object
- Object
- ALib::MainModule::ConfigurableMain
- Includes:
- Abilities
- Defined in:
- lib/alib.rb,
lib/alib-0.3.1.rb
Overview
–}}}
Class Method Summary collapse
Instance Method Summary collapse
-
#gen_template(template) ⇒ Object
–}}}.
-
#init_config(opts = @options) ⇒ Object
–}}}.
-
#post_parse_argv ⇒ Object
–}}}.
- #pre_parse_argv ⇒ Object
Methods included from Abilities
Class Method Details
.class_initialize ⇒ Object
–{{{
2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 |
# File 'lib/alib.rb', line 2640 def class_initialize #--{{{ version '0.0.0' prognam ALib::Util::prognam configfile Class::new(ALib::ConfigFile) #{ default = DATA; DATA.rewind; } config_default_path "#{ prognam }.conf" config_search_path %w(. ~ /usr/local/etc /usr/etc /etc) usage <<-usage NAME #{ prognam } v#{ version } SYNOPSIS #{ prognam } [options]+ [file]+ CONFIG default path -> #{ config_default_path } search path -> #{ config_search_path.join ' ' } usage optspec [ [ '--help', '-h', 'this message' ], [ '--log=path','-l', 'set log file - (default stderr)' ], [ '--verbosity=verbostiy', '-v', '0|fatal < 1|error < 2|warn < 3|info < 4|debug - (default info)' ], [ '--config=path', 'valid path - specify config file (default nil)' ], [ '--template=[path]', 'valid path - generate a template config file in path (default stdout)' ], ] #--}}} end |
Instance Method Details
#gen_template(template) ⇒ Object
–}}}
2712 2713 2714 2715 2716 2717 |
# File 'lib/alib.rb', line 2712 def gen_template template #--{{{ klass::configfile::gen_template(template) self #--}}} end |
#init_config(opts = @options) ⇒ Object
–}}}
2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 |
# File 'lib/alib.rb', line 2723 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_argv ⇒ Object
–}}}
2718 2719 2720 2721 2722 |
# File 'lib/alib.rb', line 2718 def post_parse_argv #--{{{ init_config #--}}} end |
#pre_parse_argv ⇒ Object
2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 |
# File 'lib/alib.rb', line 2694 def pre_parse_argv #--{{{ if(@options.has_key?('help') or @argv.first =~ %r/help/i) usage STDOUT exit EXIT_SUCCESS end if(@options.has_key?('version') or @argv.first =~ %r/version/i) STDOUT.puts self.class.version exit EXIT_SUCCESS end 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 |