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
20 def initialize(stdout, stdin, stderr, command, arguments)
21   klass = get_command_class(parse_command(command))
22   @command = klass.new(stdout, stdin, stderr, arguments)
23   @help_command = Commands::HelpCommand.new(stdout, stdin, stderr, [])
24 end
puts_red(string) click to toggle source
  # File lib/oauth/tty/cli.rb
7 def puts_red(string)
8   puts "\033[0;91m#{string}\033[0m"
9 end

Public Instance Methods

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

Private Instance Methods

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