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.



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

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.



14
15
16
# File 'lib/htty/cli.rb', line 14

def session
  @session
end

Instance Method Details

#formatted_promptObject

This is something that should belong to Display



41
42
43
# File 'lib/htty/cli.rb', line 41

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

#line(command = '') ⇒ Object

This is something that should belong to Display



36
37
38
# File 'lib/htty/cli.rb', line 36

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

#run!Object

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



25
26
27
28
29
30
31
32
33
# File 'lib/htty/cli.rb', line 25

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