module LolcatCommand
LolcatCommand — parse !lolcat subcommands and option tokens. Public: parse, usage_message Depends: LolcatRunner Tests: test/lib/lolcat_command_test.rb
Public Instance Methods
Source
# File lib/lolcat_command.rb, line 17 def parse(text) args = text.to_s.strip return { action: :help } if args.empty? parts = args.split(/\s+/) case parts[0].downcase when "help", "?" { action: :help } when "on", "enable" { action: :on } when "off", "disable" { action: :off } when "status" { action: :status } when "reset" { action: :reset } when "options", "opts", "set" tokens = parts[1..] || [] built = LolcatRunner.build_argv(tokens) return { error: built[:error] } if built[:error] { action: :options, argv: tokens, lolcat_argv: built[:argv] } when "preview", "test" { action: :preview, text: parts[1..]&.join(" ").to_s.strip } else if parts[0].start_with?("-") built = LolcatRunner.build_argv(parts) return { error: built[:error] } if built[:error] { action: :options, argv: parts, lolcat_argv: built[:argv] } else { error: usage_message } end end end
Source
# File lib/lolcat_command.rb, line 13 def usage_message "Usage: !lolcat on|off|status|reset|options <flags>|preview [text]|help" end