Class: Ing::Commands::List

Inherits:
Object
  • Object
show all
Includes:
Ing::CommonOptions
Defined in:
lib/ing/commands/list.rb

Constant Summary collapse

DEFAULTS =
{
   namespace: 'ing:commands',
   ing_file:  'ing.rb'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ing::CommonOptions

#debug, #debug?, included, #ing_file, #namespace, #require_ing_file, #require_libs, #requires

Constructor Details

#initialize(options) ⇒ List

Returns a new instance of List.



28
29
30
# File 'lib/ing/commands/list.rb', line 28

def initialize(options)
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



21
22
23
# File 'lib/ing/commands/list.rb', line 21

def options
  @options
end

#shellObject



24
25
26
# File 'lib/ing/commands/list.rb', line 24

def shell
  @shell ||= ::Ing.shell_class.new
end

Class Method Details

.specify_options(parser) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/ing/commands/list.rb', line 11

def self.specify_options(parser)
  parser.banner "List all tasks within specified namespace"
  parser.text "\nUsage:"
  parser.text "  ing list        # list all built-in ing commands"
  parser.text "  ing list rspec  # list all ing commands in rspec namespace, or"
  parser.text "  ing list --namespace rspec"
end

Instance Method Details

#beforeObject

Require each passed file or library before running and require the ing file if it exists



34
35
36
37
# File 'lib/ing/commands/list.rb', line 34

def before
  require_libs
  require_ing_file
end

#call(ns = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ing/commands/list.rb', line 39

def call(ns=nil)
  before
  mod       = _namespace_class(ns)
  data = mod.constants.map do |c|
    klass = mod.const_get(c)
    desc = (Command.new(klass).describe || '')[/.+$/]
    [ "ing #{Ing::Util.encode_class(mod)}:#{Ing::Util.encode_class_names([c])}", 
      (desc || '(no description)').chomp
    ]
  end.sort
  shell.say desc_lines(mod, data).join("\n")
end