Class: S7::S7Cli::HelpCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/s7/s7cli/command.rb

Overview

プログラムを終了するコマンドを表現する。

Instance Attribute Summary

Attributes inherited from Command

#config, #options, #world

Instance Method Summary collapse

Methods inherited from Command

#aliases, create_instance, #description, #help, #initialize, #name, #option_parser, split_name_and_argv, #usage

Methods included from GetText

#N_, #_, bindtextdomain, included

Constructor Details

This class inherits a constructor from S7::S7Cli::Command

Instance Method Details

#run(argv) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/s7/s7cli/command.rb', line 121

def run(argv)
  if argv.length > 0
    command_name = argv.shift
    command = Command.create_instance(command_name, world)
    if command
      command.help
    else
      puts(_("Unknown command: %s") % command_name)
    end
  else
    puts(_("Available commands:"))
    command_classes = @@command_classes.values.uniq.sort_by { |klass|
      klass.const_get("NAME")
    }
    command_classes.each do |klass|
      s = "  #{klass.const_get("NAME")}"
      aliases = klass.const_get("ALIASES")
      if aliases.length > 0
        s << " (#{aliases.join(", ")})"
      end
      puts(s)
    end
  end
  return true
end