Sha256: 31efce66d4982f016cb9bdc6a0c5bcf49e57f4a4fcc480d6c099f75ba639f83a

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module CyberarmEngine
  class Console
    class HelpCommand < CyberarmEngine::Console::Command
      def group
        :global
      end

      def command
        :help
      end

      def handle(arguments, console)
        console.stdin(usage(arguments.first))
      end

      def autocomplete(console)
        split = console.text_input.text.split(" ")
        if !console.text_input.text.start_with?(" ") && split.size == 2
          list = console.abbrev_search(Command.list_commands.map { |cmd| cmd.command.to_s }, split.last)
          if list.size == 1
            console.text_input.text = "#{split.first} #{list.first} "
          elsif list.size > 1
            console.stdin(list.map { |cmd| Style.highlight(cmd) }.join(", "))
          end
        end
      end

      def usage(command = nil)
        if command
          if cmd = Command.find(command)
            cmd.usage
          else
            "#{Style.error(command)} is not a command"
          end
        else
          "Available commands:\n#{Command.list_commands.map { |cmd| Style.highlight(cmd.command).to_s }.join(', ')}"
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cyberarm_engine-0.24.4 lib/cyberarm_engine/console/commands/help_command.rb
cyberarm_engine-0.24.3 lib/cyberarm_engine/console/commands/help_command.rb
cyberarm_engine-0.24.2 lib/cyberarm_engine/console/commands/help_command.rb
cyberarm_engine-0.24.1 lib/cyberarm_engine/console/commands/help_command.rb
cyberarm_engine-0.24.0 lib/cyberarm_engine/console/commands/help_command.rb
cyberarm_engine-0.23.0 lib/cyberarm_engine/console/commands/help_command.rb
cyberarm_engine-0.22.0 lib/cyberarm_engine/console/commands/help_command.rb
cyberarm_engine-0.21.0 lib/cyberarm_engine/console/commands/help_command.rb
cyberarm_engine-0.20.0 lib/cyberarm_engine/console/commands/help_command.rb
cyberarm_engine-0.19.1 lib/cyberarm_engine/console/commands/help_command.rb