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.



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

def initialize(options)
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#shellObject



31
32
33
# File 'lib/ing/commands/list.rb', line 31

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

Class Method Details

.specify_options(parser) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ing/commands/list.rb', line 11

def self.specify_options(parser)
  parser.banner "List all tasks by name or in specified namespace"
  parser.text "\nUsage:"
  parser.text "  ing list                # list all known commands that have a description"
  parser.text "  ing list -n rspec       # list all commands in rspec namespace"
  parser.text "  ing list rspec          # list commands that match /.*rspec/ (in any namespace)"
  parser.text "  ing list rspec --all    # list modules that don't have a description (not recommended!)"
  parser.text "  ing list -n rspec conv  # list commands that match /.*conv/ in rspec namespace"
  parser.text "\nOptions:"
  parser.opt :all, "List all tasks including modules that don't have a description", 
             :default => false
  parser.opt :strict, "List only tasks that are strictly within specified namespace", 
             :default => false
end

Instance Method Details

#beforeObject

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



41
42
43
44
# File 'lib/ing/commands/list.rb', line 41

def before
  require_libs
  require_ing_file
end

#call(s = nil) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/ing/commands/list.rb', line 46

def call(s=nil)
  before
  if !options[:namespace_given]
    search_all s
  else
    search s
  end
end

#search(s, recurse = !options[:strict])) ⇒ Object



55
56
57
# File 'lib/ing/commands/list.rb', line 55

def search(s, recurse=!options[:strict])
  _do_search(_namespace_class, %r|.*#{s}|, recurse)
end

#search_all(s, recurse = !options[:strict])) ⇒ Object



59
60
61
# File 'lib/ing/commands/list.rb', line 59

def search_all(s, recurse=!options[:strict])
  _do_search(::Object, %r|.*#{s}|, recurse)
end