Class: HTTY::CLI

Inherits:
Object
  • Object
show all
Includes:
Display
Defined in:
lib/htty/cli.rb,
lib/htty/cli/display.rb,
lib/htty/cli/command.rb,
lib/htty/cli/commands.rb,
lib/htty/cli/commands/cd.rb,
lib/htty/cli/url_escaping.rb,
lib/htty/cli/commands/put.rb,
lib/htty/cli/commands/get.rb,
lib/htty/cli/commands/post.rb,
lib/htty/cli/commands/help.rb,
lib/htty/cli/commands/exit.rb,
lib/htty/cli/commands/undo.rb,
lib/htty/cli/commands/quit.rb,
lib/htty/cli/commands/form.rb,
lib/htty/cli/commands/patch.rb,
lib/htty/cli/commands/reuse.rb,
lib/htty/cli/commands/status.rb,
lib/htty/cli/commands/follow.rb,
lib/htty/cli/commands/delete.rb,
lib/htty/cli/commands/history.rb,
lib/htty/cli/commands/address.rb,
lib/htty/cli/commands/cookies.rb,
lib/htty/cli/commands/form_add.rb,
lib/htty/cli/commands/http_put.rb,
lib/htty/cli/commands/path_set.rb,
lib/htty/cli/body_open_command.rb,
lib/htty/cli/commands/host_set.rb,
lib/htty/cli/commands/http_get.rb,
lib/htty/cli/commands/body_set.rb,
lib/htty/cli/commands/port_set.rb,
lib/htty/cli/commands/http_head.rb,
lib/htty/cli/commands/body_edit.rb,
lib/htty/cli/commands/query_set.rb,
lib/htty/cli/commands/http_post.rb,
lib/htty/cli/commands/query_add.rb,
lib/htty/cli/commands/header_set.rb,
lib/htty/cli/commands/body_unset.rb,
lib/htty/cli/commands/cookie_add.rb,
lib/htty/cli/commands/http_trace.rb,
lib/htty/cli/commands/scheme_set.rb,
lib/htty/cli/commands/http_patch.rb,
lib/htty/cli/commands/body_clear.rb,
lib/htty/cli/commands/form_clear.rb,
lib/htty/cli/http_method_command.rb,
lib/htty/cli/commands/headers_set.rb,
lib/htty/cli/commands/http_delete.rb,
lib/htty/cli/commands/query_unset.rb,
lib/htty/cli/commands/form_remove.rb,
lib/htty/cli/commands/cookies_add.rb,
lib/htty/cli/commands/cookies_use.rb,
lib/htty/cli/commands/query_clear.rb,
lib/htty/cli/commands/userinfo_set.rb,
lib/htty/cli/commands/query_remove.rb,
lib/htty/cli/commands/http_options.rb,
lib/htty/cli/commands/fragment_set.rb,
lib/htty/cli/commands/header_unset.rb,
lib/htty/cli/commands/body_request.rb,
lib/htty/cli/commands/headers_unset.rb,
lib/htty/cli/commands/cookie_remove.rb,
lib/htty/cli/commands/cookies_clear.rb,
lib/htty/cli/commands/body_response.rb,
lib/htty/cli/commands/headers_clear.rb,
lib/htty/cli/commands/userinfo_unset.rb,
lib/htty/cli/commands/userinfo_clear.rb,
lib/htty/cli/commands/cookies_remove.rb,
lib/htty/cli/commands/fragment_unset.rb,
lib/htty/cli/commands/fragment_clear.rb,
lib/htty/cli/commands/query_unset_all.rb,
lib/htty/cli/commands/form_remove_all.rb,
lib/htty/cli/commands/headers_request.rb,
lib/htty/cli/commands/history_verbose.rb,
lib/htty/cli/commands/headers_response.rb,
lib/htty/cli/commands/ssl_verification.rb,
lib/htty/cli/commands/headers_unset_all.rb,
lib/htty/cli/commands/body_request_open.rb,
lib/htty/cli/commands/cookies_remove_all.rb,
lib/htty/cli/commands/body_response_open.rb,
lib/htty/cli/commands/ssl_verification_on.rb,
lib/htty/cli/commands/ssl_verification_off.rb

Overview

Encapsulates the command-line interface to htty.

Defined Under Namespace

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

Constant Summary

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.



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

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.



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

def session
  @session
end

Instance Method Details

#formatted_promptObject

This is something that should belong to Display



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

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

#line(command = '') ⇒ Object

This is something that should belong to Display



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

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

#run!Object

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



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

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