Class: Nanoc2::CLI::InfoCommand

Inherits:
Cri::Command
  • Object
show all
Defined in:
lib/nanoc2/cli/commands/info.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#aliasesObject



9
10
11
# File 'lib/nanoc2/cli/commands/info.rb', line 9

def aliases
  []
end

#long_descObject



17
18
19
20
21
# File 'lib/nanoc2/cli/commands/info.rb', line 17

def long_desc
  'Show a list of available plugins, including filters, data sources ' +
  'and routers. If the current directory contains a nanoc web site, ' +
  'the plugins defined in this site will be shown as well.'
end

#nameObject



5
6
7
# File 'lib/nanoc2/cli/commands/info.rb', line 5

def name
  'info'
end

#option_definitionsObject



27
28
29
# File 'lib/nanoc2/cli/commands/info.rb', line 27

def option_definitions
  []
end

#run(options, arguments) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/nanoc2/cli/commands/info.rb', line 31

def run(options, arguments)
  # Check arguments
  if arguments.size != 0
    $stderr.puts "usage: #{usage}"
    exit 1
  end

  # Get list of plugins (before and after)
  plugins_before  = find_all_plugins
  @base.site
  plugins_after   = find_all_plugins

  # Get structured list of plugins
  plugins = {}
  plugin_classes.each do |klass|
    plugins[klass] = {
      :builtin  => plugins_before[klass],
      :custom   => plugins_after[klass] - plugins_before[klass]
    }
  end

  # Find longest name
  max_length = plugins.values.map { |k| k.values }.flatten.map { |k| k.identifiers.join(', ').length }.max + 2

  PLUGIN_CLASS_ORDER.each do |superclass|
    structured_plugins = plugins[superclass]

    # Print kind
    kind = name_for_plugin_class(superclass)
    puts "#{kind}:"
    puts

    # Print plugins organised by subtype
    [ :builtin, :custom ].each do |type|
      # Find relevant plugins
      subclasses = structured_plugins[type]

      # Print type
      puts "  #{type}:"
      if subclasses.empty?
        puts "    (none)"
        next
      end

      # Print plugins
      subclasses.sort_by { |k| k.identifier.to_s }.each do |klass|
        # Get data
        is_custom   = !plugins_before[superclass].include?(klass)
        klass_name  = klass.to_s
        klass_id    = klass.identifiers.join(', ')

        # Display
        puts sprintf("    %-#{max_length}s (%s)", klass_id, klass_name)
      end
    end

    puts
  end
end

#short_descObject



13
14
15
# File 'lib/nanoc2/cli/commands/info.rb', line 13

def short_desc
  'show info about available plugins'
end

#usageObject



23
24
25
# File 'lib/nanoc2/cli/commands/info.rb', line 23

def usage
  "nanoc2 info"
end