Sha256: 3226c087e7f38dab8ca4c300a127f0c773fbeb9bb5687adf4f9a450b813ff2e0

Contents?: true

Size: 1.65 KB

Versions: 20

Compression:

Stored size: 1.65 KB

Contents

# encoding: utf-8

module Nanoc3::CLI::Commands

  class Help < Cri::Command

    def name
      'help'
    end

    def aliases
      []
    end

    def short_desc
      'show help for a command'
    end

    def long_desc
      'Show help for the given command, or show general help. When no ' +
      'command is given, a list of available commands is displayed, as ' +
      'well as a list of global commandline options. When a command is ' +
      'given, a command description as well as command-specific ' +
      'commandline options are shown.'
    end

    def usage
      "nanoc3 help [options] [command]"
    end

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

      if arguments.length == 0
        # Build help text
        text = ''

        # Add title
        text << "nanoc, a static site compiler written in Ruby.\n"

        # Add available commands
        text << "\n"
        text << "Available commands:\n"
        text << "\n"
        @base.commands.sort.each do |command|
          text << sprintf("    %-20s %s\n", command.name, command.short_desc)
        end

        # Add global options
        text << "\n"
        text << "Global options:\n"
        text << "\n"
        @base.global_option_definitions.sort { |x,y| x[:long] <=> y[:long] }.each do |opt_def|
          text << sprintf("    -%1s --%-15s %s\n", opt_def[:short], opt_def[:long], opt_def[:desc])
        end

        # Display text
        puts text
      elsif arguments.length == 1
        command = @base.command_named(arguments[0])
        puts command.help
      end
    end

  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nanoc3-3.1.9 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.8 lib/nanoc3/cli/commands/help.rb
nanoc3-3.2.0a4 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.7 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.6 lib/nanoc3/cli/commands/help.rb
nanoc3-3.2.0a3 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.5 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.4 lib/nanoc3/cli/commands/help.rb
nanoc3-3.2.0a2 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.3 lib/nanoc3/cli/commands/help.rb
nanoc3-3.2.0a1 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.2 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.1 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.0 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.0rc1 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.0b2 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.0b1 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.0a3 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.0a2 lib/nanoc3/cli/commands/help.rb
nanoc3-3.1.0a1 lib/nanoc3/cli/commands/help.rb