Class: DLDInternet::Thor::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/dldinternet/thor/command.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = [], local_options = {}, config = {})
  super(args,local_options,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

.invocationsObject

Returns the value of attribute invocations.



15
16
17
# File 'lib/dldinternet/thor/command.rb', line 15

def invocations
  @invocations
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



54
55
56
# File 'lib/dldinternet/thor/command.rb', line 54

def format
  @format
end

#formatterObject

Returns the value of attribute formatter.



54
55
56
# File 'lib/dldinternet/thor/command.rb', line 54

def formatter
  @formatter
end

#headerObject

Returns the value of attribute header.



54
55
56
# File 'lib/dldinternet/thor/command.rb', line 54

def header
  @header
end

#writerObject

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, options
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:

Raises:

  • (::Thor::InvocationError)


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 = banner(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

.namespaceObject



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