svenfuchs/cl

View on GitHub
lib/cl/help/cmds.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'cl/help/table'
require 'cl/help/usage'

class Cl
  class Help
    class Cmds < Struct.new(:ctx, :cmds)
      HEAD = %(Type "%s help COMMAND [SUBCOMMAND]" for more details:\n)

      def format
        [head, Table.new(list).format].join("\n")
      end

      def head
        HEAD % ctx.name
      end

      def list
        cmds.any? ? cmds.map { |cmd| format_cmd(cmd) } : [['[no commands]']]
      end

      def format_cmd(cmd)
        ["#{Usage.new(ctx, cmd).format.first}", cmd.summary]
      end
    end
  end
end