Class: HTTY::CLI::Commands::Reuse
- Inherits:
-
HTTY::CLI::Command
- Object
- HTTY::CLI::Command
- HTTY::CLI::Commands::Reuse
- Includes:
- Display
- Defined in:
- lib/htty/cli/commands/reuse.rb
Overview
Encapsulates the reuse command.
Constant Summary
Constant Summary
Constants included from Display
Instance Attribute Summary
Attributes inherited from HTTY::CLI::Command
Class Method Summary (collapse)
-
+ (Object) category
Returns the name of a category under which help for the reuse command should appear.
-
+ (Object) command_line_arguments
Returns the arguments for the command-line usage of the reuse command.
-
+ (Object) help
Returns the help text for the reuse command.
-
+ (Object) help_extended
Returns the extended help text for the reuse command.
-
+ (Object) see_also_commands
Returns related command classes for the reuse command.
Instance Method Summary (collapse)
-
- (Object) perform
Performs the reuse command.
Methods included from Display
#format, #indent, #logotype, #normal, #notice, #pluralize, #prompt, #rescuing_from, #say, #say_goodbye, #say_header, #say_hello, #show_headers, #show_request, #show_response, #strong, #word_wrap, #word_wrap_indented
Methods inherited from HTTY::CLI::Command
#add_request_if_new, alias_for, aliases, build_for, command_line, complete_for?, #initialize, notify_if_cookies_cleared, raw_name
Constructor Details
This class inherits a constructor from HTTY::CLI::Command
Class Method Details
+ (Object) category
Returns the name of a category under which help for the reuse command should appear.
19 20 21 |
# File 'lib/htty/cli/commands/reuse.rb', line 19 def self.category 'Navigation' end |
+ (Object) command_line_arguments
Returns the arguments for the command-line usage of the reuse command.
24 25 26 |
# File 'lib/htty/cli/commands/reuse.rb', line 24 def self.command_line_arguments 'INDEX' end |
+ (Object) help
Returns the help text for the reuse command.
29 30 31 |
# File 'lib/htty/cli/commands/reuse.rb', line 29 def self.help 'Copies a previous request by the index number shown in history' end |
+ (Object) help_extended
Returns the extended help text for the reuse command.
34 35 36 37 38 39 40 41 |
# File 'lib/htty/cli/commands/reuse.rb', line 34 def self.help_extended 'Copies the properties of a previous request to be used for the request, ' + 'using the request index number shown in history. Does not communicate ' + "with the host.\n" + "\n" + 'The argument is an index number that appears when you type ' + "#{strong HTTY::CLI::Commands::History.command_line}." end |
+ (Object) see_also_commands
Returns related command classes for the reuse command.
44 45 46 |
# File 'lib/htty/cli/commands/reuse.rb', line 44 def self.see_also_commands [HTTY::CLI::Commands::History, HTTY::CLI::Commands::HistoryVerbose] end |
Instance Method Details
- (Object) perform
Performs the reuse command.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/htty/cli/commands/reuse.rb', line 49 def perform unless arguments.length == 1 raise ArgumentError, "wrong number of arguments (#{arguments.length} for 1)" end requests = session.requests requests_with_responses = requests.select do |r| r.response end raise 'no requests in history' if requests_with_responses.empty? index = arguments.first.to_i unless (1..requests_with_responses.length).include?(index) raise ArgumentError, "index must be between 1 and #{requests_with_responses.length}" end add_request_if_new do requests[index - 1].send :dup_without_response end puts notice("Using a copy of request ##{index}") self end |