module ThemeCommand
ThemeCommand — parse !theme subcommands. Public: parse, usage_message Depends: (none) Tests: test/lib/theme_command_test.rb
Public Instance Methods
Source
# File lib/theme_command.rb, line 15 def parse(args) text = args.to_s.strip return { action: :help } if text.empty? || text.casecmp("help").zero? parts = text.split(/\s+/, 2) verb = parts[0].downcase rest = parts[1].to_s.strip case verb when "list" { action: :list } when "show" return { error: usage_message } if rest.empty? { action: :show, name: rest.split(/\s+/).first.downcase } when "active" { action: :active } when "use" return { error: usage_message } if rest.empty? { action: :use, name: rest.split(/\s+/).first.downcase } when "paint" tokens = rest.split(/\s+/) return { error: usage_message } if tokens.empty? result = { action: :paint, name: tokens[0].downcase } result[:plugin] = tokens[1].downcase if tokens[1] result when "analyse" name = rest.empty? ? nil : rest.split(/\s+/).first.downcase { action: :analyse, name: name } when "generate" seed = rest.empty? ? nil : rest.split(/\s+/).first { action: :generate, seed: seed } when "save" return { error: usage_message } if rest.empty? { action: :save, name: rest.split(/\s+/).first.downcase } else { error: usage_message } end end
Source
# File lib/theme_command.rb, line 11 def usage_message "Usage: !theme list|show|active|use|paint|analyse|generate|save|help" end