Class: Tb::Cmd
- Inherits:
-
Object
- Object
- Tb::Cmd
- Defined in:
- lib/tb/cmdutil.rb
Overview
Copyright © 2011-2012 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: Ls, SVNLOGListener
Constant Summary collapse
- GIT_LOG_FORMAT_SPEC =
[ %w[commit %H], %w[tree %T], %w[parents %P], %w[author-name %an], %w[author-email %ae], %w[author-date %ai], %w[committer-name %cn], %w[committer-email %ce], %w[committer-date %ci], %w[ref-names %d], %w[encoding %e], %w[subject %s], %w[body %b], %w[raw-body %B], %w[notes %N], %w[reflog-selector %gD], %w[reflog-subject %gs],
- GIT_LOG_PRETTY_FORMAT =
'format:%x01commit-separator%x01%n' + Tb::Cmd::GIT_LOG_FORMAT_SPEC.map {|k, v| "#{k}:%w(0,0,1)#{v}%w(0,0,0)%n" }.join('') + "end-commit%n"
- GIT_LOG_HEADER =
Tb::Cmd::GIT_LOG_FORMAT_SPEC.map {|k, v| k } + ['files']
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.
91 92 93 |
# File 'lib/tb/cmdutil.rb', line 91 def default_option @default_option end |
.subcommands ⇒ Object (readonly)
Returns the value of attribute subcommands.
90 91 92 |
# File 'lib/tb/cmdutil.rb', line 90 def subcommands @subcommands end |
.verbose_help ⇒ Object (readonly)
Returns the value of attribute verbose_help.
92 93 94 |
# File 'lib/tb/cmdutil.rb', line 92 def verbose_help @verbose_help end |
Class Method Details
.def_vhelp(subcommand, str) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/tb/cmdutil.rb', line 77 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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tb/cmdutil.rb', line 55 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
46 47 48 49 50 51 52 53 |
# File 'lib/tb/cmdutil.rb', line 46 def self.init_option class << Tb::Cmd Tb::Cmd.default_option.each {|k, v| attr_accessor k } end reset_option end |
.reset_option ⇒ Object
40 41 42 43 44 |
# File 'lib/tb/cmdutil.rb', line 40 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
84 85 86 |
# File 'lib/tb/cmdutil.rb', line 84 def self.subcommand_send(prefix, subcommand, *args, &block) self.send(prefix + "_" + subcommand.gsub(/-/, '_'), *args, &block) end |