Added DebugCommand, added support for 'subcommands'

This commit is contained in:
2019-08-07 17:06:40 -05:00
parent 80576a211a
commit 3e6ff5bd4a
3 changed files with 171 additions and 7 deletions

View File

@@ -0,0 +1,31 @@
class IMICFPS
class Commands
class DebugCommand < Command
def group
:global
end
def command
:debug
end
def setup
subcommand(:boundingboxes, :boolean)
subcommand(:wireframe, :boolean)
subcommand(:fps, :boolean)
subcommand(:stats, :boolean)
subcommand(:motd, :string)
subcommand(:mode, :integer)
subcommand(:gravity, :decimal)
end
def handle(arguments, console)
handle_subcommand(arguments, console)
end
def usage
string = "debug\n #{@subcommands.map { |sub| sub.usage }.join("\n ")}"
end
end
end
end

View File

@@ -1,9 +1,6 @@
class IMICFPS
class Commands
class HelpCommand < Command
def initialize
end
def group
:global
end
@@ -13,11 +10,17 @@ class IMICFPS
end
def handle(arguments, console)
console.stdin(usage)
console.stdin(usage(arguments.first))
end
def usage
"HELP\ncommand [arguments]\ncommand subcommand [argument]"
def usage(command = nil)
if command
if cmd = Command.find(command)
cmd.usage
end
else
"Available commands:\n#{Command.list_commands.map { |cmd| "#{Style.highlight(cmd.command)}" }.join(', ')}"
end
end
end
end