Class: DLDInternet::Thor::Command
- Inherits:
-
Thor
- Object
- Thor
- DLDInternet::Thor::Command
- Defined in:
- lib/dldinternet/thor/command.rb
Class Attribute Summary collapse
-
.invocations ⇒ Object
Returns the value of attribute invocations.
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#header ⇒ Object
Returns the value of attribute header.
-
#writer ⇒ Object
Returns the value of attribute writer.
Class Method Summary collapse
-
.command_help(shell, command_name, invocations = []) ⇒ Object
def command(scommand, usage, description, options = {}, &block) desc usage, description, options define_method(scommand) do |*args| args, opts = ::Thor::Arguments.split(args) block.call(args) end end alias_method :task, :command.
-
.handle_argument_error(command, error, args, arity) ⇒ Object
:nodoc:.
- .namespace ⇒ Object
Instance Method Summary collapse
- #help(command = nil, subcommand = false) ⇒ Object
-
#initialize(args = [], local_options = {}, config = {}) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(args = [], local_options = {}, config = {}) ⇒ Command
Returns a new instance of Command.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dldinternet/thor/command.rb', line 56 def initialize(args = [], = {}, config = {}) super(args,,config) @log_level = :warn #|| @config[:log_level].to_sym @formatter ||= ->(hsh, opts) { default_formatter(hsh, opts) } @writer ||= ->(str) { puts str } @header ||= ->(res, fmtr=nil) { default_header(res, fmtr) } @format ||= ->(res, fmtr=nil) { default_format(res, nil, fmtr) } end |
Class Attribute Details
.invocations ⇒ Object
Returns the value of attribute invocations.
15 16 17 |
# File 'lib/dldinternet/thor/command.rb', line 15 def invocations @invocations end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
54 55 56 |
# File 'lib/dldinternet/thor/command.rb', line 54 def format @format end |
#formatter ⇒ Object
Returns the value of attribute formatter.
54 55 56 |
# File 'lib/dldinternet/thor/command.rb', line 54 def formatter @formatter end |
#header ⇒ Object
Returns the value of attribute header.
54 55 56 |
# File 'lib/dldinternet/thor/command.rb', line 54 def header @header end |
#writer ⇒ Object
Returns the value of attribute writer.
54 55 56 |
# File 'lib/dldinternet/thor/command.rb', line 54 def writer @writer end |
Class Method Details
.command_help(shell, command_name, invocations = []) ⇒ Object
def command(scommand, usage, description, options = {}, &block)
desc usage, description,
define_method(scommand) do |*args|
args, opts = ::Thor::Arguments.split(args)
block.call(args)
end
end alias_method :task, :command
31 32 33 34 |
# File 'lib/dldinternet/thor/command.rb', line 31 def command_help(shell, command_name, invocations=[]) super(shell, command_name) 0 end |
.handle_argument_error(command, error, args, arity) ⇒ Object
:nodoc:
36 37 38 39 40 41 42 43 44 |
# File 'lib/dldinternet/thor/command.rb', line 36 def handle_argument_error(command, error, args, arity) #:nodoc: command_s = (command) # msg = "ERROR: \"#{basename} #{command.name}\" was called with " msg = "ERROR: \"#{command_s}\" was called with " msg << "no arguments" if args.empty? msg << "arguments " << args.inspect unless args.empty? msg << "\nUsage: #{command_s}" raise ::Thor::InvocationError, msg end |
.namespace ⇒ Object
17 18 19 20 |
# File 'lib/dldinternet/thor/command.rb', line 17 def namespace parts = self.name.split(/::/) parts[parts.size > 2 ? -2 : -1].downcase end |
Instance Method Details
#help(command = nil, subcommand = false) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dldinternet/thor/command.rb', line 74 def help(command = nil, subcommand = false) ::DLDInternet::Thor::Command.invocations = @_invocations.dup.map{ |_,v| v[0]} # self.class.invocations[-1] = command ::DLDInternet::Thor::Command.invocations.pop if ::DLDInternet::Thor::Command.invocations[-1].eql?('help') ::DLDInternet::Thor::Command.invocations.pop if ::DLDInternet::Thor::Command.invocations[-1].eql?(command) || (!command && subcommand) super(command, subcommand) # if command # if self.class.subcommands.include? command # self.class.subcommand_classes[command].help(shell, true) # else # self.class.command_help(shell, command, invocations) # end # else # self.class.help(shell, subcommand) # end 0 end |