Class: Tb::Cmd
- Inherits:
-
Object
- Object
- Tb::Cmd
- Defined in:
- lib/tb/cmdutil.rb
Overview
Copyright © 2011 Tanaka Akira <[email protected]>
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Defined Under Namespace
Classes: SVNLOGListener
Class Attribute Summary collapse
-
.default_option ⇒ Object
readonly
Returns the value of attribute default_option.
-
.subcommands ⇒ Object
readonly
Returns the value of attribute subcommands.
-
.verbose_help ⇒ Object
readonly
Returns the value of attribute verbose_help.
Class Method Summary collapse
- .def_vhelp(subcommand, str) ⇒ Object
- .define_common_option(op, short_opts, *long_opts) ⇒ Object
- .init_option ⇒ Object
- .reset_option ⇒ Object
- .subcommand_send(prefix, subcommand, *args, &block) ⇒ Object
Class Attribute Details
.default_option ⇒ Object (readonly)
Returns the value of attribute default_option.
87 88 89 |
# File 'lib/tb/cmdutil.rb', line 87 def default_option @default_option end |
.subcommands ⇒ Object (readonly)
Returns the value of attribute subcommands.
86 87 88 |
# File 'lib/tb/cmdutil.rb', line 86 def subcommands @subcommands end |
.verbose_help ⇒ Object (readonly)
Returns the value of attribute verbose_help.
88 89 90 |
# File 'lib/tb/cmdutil.rb', line 88 def verbose_help @verbose_help end |
Class Method Details
.def_vhelp(subcommand, str) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/tb/cmdutil.rb', line 73 def self.def_vhelp(subcommand, str) if @verbose_help[subcommand] raise ArgumentError, "verbose_help[#{subcommand.dump}] already defined." end @verbose_help[subcommand] = str end |
.define_common_option(op, short_opts, *long_opts) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/tb/cmdutil.rb', line 51 def self.define_common_option(op, short_opts, *long_opts) if short_opts.include? "h" op.def_option('-h', '--help', 'show help message (-hh for verbose help)') { Tb::Cmd.opt_help += 1 } end if short_opts.include? "N" op.def_option('-N', 'use numeric field name') { Tb::Cmd.opt_N = true } end if short_opts.include? "o" op.def_option('-o filename', 'output to specified filename') {|filename| Tb::Cmd.opt_output = filename } end if long_opts.include? "--no-pager" op.def_option('--no-pager', 'don\'t use pager') { Tb::Cmd.opt_no_pager = true } end opts = [] opts << '-d' if short_opts.include?('d') opts << '--debug' if long_opts.include?('--debug') if !opts.empty? op.def_option(*(opts + ['show debug message'])) { Tb::Cmd.opt_debug += 1 } end end |
.init_option ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/tb/cmdutil.rb', line 42 def self.init_option class << Tb::Cmd Tb::Cmd.default_option.each {|k, v| attr_accessor k } end reset_option end |
.reset_option ⇒ Object
36 37 38 39 40 |
# File 'lib/tb/cmdutil.rb', line 36 def self.reset_option @default_option.each {|k, v| instance_variable_set("@#{k}", Marshal.load(Marshal.dump(v))) } end |
.subcommand_send(prefix, subcommand, *args, &block) ⇒ Object
80 81 82 |
# File 'lib/tb/cmdutil.rb', line 80 def self.subcommand_send(prefix, subcommand, *args, &block) self.send(prefix + "_" + subcommand.gsub(/-/, '_'), *args, &block) end |