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.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/dldinternet/thor/command.rb', line 69

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.



19
20
21
# File 'lib/dldinternet/thor/command.rb', line 19

def invocations
  @invocations
end

Instance Attribute Details

#cassetteObject (readonly)

Returns the value of attribute cassette.



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

def cassette
  @cassette
end

#formatObject

Returns the value of attribute format.



67
68
69
# File 'lib/dldinternet/thor/command.rb', line 67

def format
  @format
end

#formatterObject

Returns the value of attribute formatter.



67
68
69
# File 'lib/dldinternet/thor/command.rb', line 67

def formatter
  @formatter
end

#headerObject

Returns the value of attribute header.



67
68
69
# File 'lib/dldinternet/thor/command.rb', line 67

def header
  @header
end

#vcr_loggerObject (readonly)

Returns the value of attribute vcr_logger.



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

def vcr_logger
  @vcr_logger
end

#writerObject

Returns the value of attribute writer.



67
68
69
# File 'lib/dldinternet/thor/command.rb', line 67

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



35
36
37
38
# File 'lib/dldinternet/thor/command.rb', line 35

def command_help(shell, command_name, invocations=[])
  super(shell, command_name)
  0
end

.dynamic_command_classObject

:nodoc:



40
41
42
# File 'lib/dldinternet/thor/command.rb', line 40

def dynamic_command_class #:nodoc:
  ::DLDInternet::Thor::DynamicCommand
end

.handle_argument_error(command, error, args, arity) ⇒ Object

:nodoc:

Raises:

  • (::Thor::InvocationError)


44
45
46
47
48
49
50
51
52
# File 'lib/dldinternet/thor/command.rb', line 44

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

.handle_no_command_error(command, has_namespace = $thor_runner) ⇒ Object

:nodoc:

Raises:

  • (::Thor::UndefinedCommandError)


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

def handle_no_command_error(command, has_namespace = $thor_runner) #:nodoc:
  raise ::Thor::UndefinedCommandError, "Could not find command #{command.inspect} in #{namespace.inspect} namespace." if has_namespace
  raise ::Thor::UndefinedCommandError, "Could not find command #{command.inspect}."
end

.namespaceObject



21
22
23
24
# File 'lib/dldinternet/thor/command.rb', line 21

def namespace
  parts = self.name.split(/::/)
  parts[parts.size > 2 ? -2 : -1].downcase
end

Instance Method Details

#help(command = nil, subcommand = false) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/dldinternet/thor/command.rb', line 87

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