Class: HTTY::CLI

Inherits:
Object
  • Object
show all
Includes:
Display
Defined in:
lib/htty/cli.rb

Overview

Encapsulates the command-line interface to htty.

Defined Under Namespace

Modules: BodyOpenCommand, Commands, Display, HTTPMethodCommand, InputDevice, UrlEscaping Classes: Command

Constant Summary

Constants included from Display

Display::FORMATS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Display

#break, #format, #formatted_prompt_for, #indent, #logotype, #normal, #notice, #pluralize, #rescuing_from, #say, #say_goodbye, #say_header, #say_hello, #show_headers, #show_request, #show_response, #strong, #word_wrap, #word_wrap_indented

Constructor Details

#initialize(command_line_arguments) ⇒ CLI

Instantiates a new HTTY::CLI with the specified command_line_arguments.



20
21
22
23
24
# File 'lib/htty/cli.rb', line 20

def initialize(command_line_arguments)
  handle_version(command_line_arguments)
  handle_help(command_line_arguments)
  initialize_session(command_line_arguments)
end

Instance Attribute Details

#sessionObject (readonly)

Returns the HTTY::Session created from command-line arguments.



17
18
19
# File 'lib/htty/cli.rb', line 17

def session
  @session
end

Instance Method Details

#formatted_promptObject

This is something that should belong to Display



44
45
46
# File 'lib/htty/cli.rb', line 44

def formatted_prompt
  formatted_prompt_for(@session.requests.last)
end

#line(command = '') ⇒ Object

This is something that should belong to Display



39
40
41
# File 'lib/htty/cli.rb', line 39

def line(command = '')
   puts formatted_prompt + command
end

#run!Object

Takes over STDIN, STDOUT, and STDERR to expose #session to command-line interaction.



28
29
30
31
32
33
34
35
36
# File 'lib/htty/cli.rb', line 28

def run!
  say_hello
  catch :quit do
    HTTY::CLI::InputDevice.new(self).commands do |command_line|
      run_command_line(command_line)
    end
  end
  say_goodbye
end