Module: StdCmd::Help

Defined in:
lib/command-set/standard-commands.rb

Constant Summary collapse

@@set =
nil

Class Method Summary collapse

Class Method Details

.define_commandsObject



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
# File 'lib/command-set/standard-commands.rb', line 34

def self.define_commands
  return @@set ||= Command::CommandSet.define_commands do
    command("help") do
      optional.multiword_argument(:terms) do |terms,subject|
        prefix = terms.pop
        subject.command_set.completion_list(terms, prefix, subject)
      end

      subject_methods :interpreter_behavior, :command_set

      action do
        width = (subject.interpreter_behavior)[:screen_width]
        puts
        if(terms.nil? || terms.empty?)
          subject.command_set.documentation(width).each do |docline|
            puts docline
          end
        else
          command = subject.command_set.find_command(terms)
          docs = command.documentation(width, terms)
          docs.each do |docline|
            puts docline
          end
        end
        puts
      end

      doesnt_undo

      document <<-EOH
      Returns a hopefully helpful description of the command indicated
    EOH
    end
  end
end