class OAuth::TTY::CLI

Constants

ALIASES

Public Class Methods

new(stdout, stdin, stderr, command, arguments) click to toggle source
   # File lib/oauth/tty/cli.rb
18 def initialize(stdout, stdin, stderr, command, arguments)
19   klass = get_command_class(parse_command(command))
20   @command = klass.new(stdout, stdin, stderr, arguments)
21   @help_command = Commands::HelpCommand.new(stdout, stdin, stderr, [])
22 end
puts_red(string) click to toggle source
  # File lib/oauth/tty/cli.rb
6 def self.puts_red(string)
7   puts "\033[0;91m#{string}\033[0m"
8 end

Public Instance Methods

run() click to toggle source
   # File lib/oauth/tty/cli.rb
24 def run
25   @command.run
26 end

Private Instance Methods

get_command_class(command) click to toggle source
   # File lib/oauth/tty/cli.rb
30 def get_command_class(command)
31   Object.const_get("OAuth::TTY::Commands::#{command.capitalize}Command")
32 end
parse_command(command) click to toggle source
   # File lib/oauth/tty/cli.rb
34 def parse_command(command)
35   case command = command.to_s.downcase
36   when "--version", "-v"
37     "version"
38   when "--help", "-h", nil, ""
39     "help"
40   when *ALIASES.keys
41     ALIASES[command]
42   when *ALIASES.values
43     command
44   else
45     OAuth::TTY::CLI.puts_red("Command '#{command}' not found")
46     "help"
47   end
48 end