Class: Morpheus::Cli::HistoryCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/commands/history_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from CliCommand

#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Instance Method Details

#handle(args) ⇒ Object

todo: support all the other :list options too, not just max AND start logging every terminal command, not just shell…



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/morpheus/cli/commands/history_command.rb', line 12

def handle(args)
  options = {show_pagination:false}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = "Usage: #{prog_name} #{command_name} [search]"
    # -n is a hidden alias for -m
    opts.on( '-n', '--max-commands MAX', "Alias for -m, --max option." ) do |val|
      options[:max] = val
    end
    opts.add_hidden_option('-n')
    opts.on( '-p', '--pagination', "Display pagination and count info eg. Viewing 1-25 of 42" ) do
      options[:show_pagination] = true
    end
    opts.on( nil, '--flush', "Flush history, purges entire shell history file." ) do
      options[:do_flush] = true
    end
    build_common_options(opts, options, [:list, :auto_confirm])
    opts.footer = <<-EOT
Print command history.
The --flush option can be used to purge the history.

Examples: 
  history
  history -m 100
  history "instances list"
  history --flush

The most recently executed commands are seen by default.  Use --desc to see the oldest commands.
EOT
  end
  optparse.parse!(args)
  # verify_args!(args:args, count: 0, optparse:optparse)
  if args.count > 0
    options[:phrase] = args.join(" ")
  end
  if options[:do_flush]
    command_count = Morpheus::Cli::Shell.instance.history_commands_count
    unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to flush your command history (#{format_number(command_count)} #{command_count == 1 ? 'command' : 'commands'})?")
      return 9, "aborted command"
    end
    flush_n = options[:max] ? options[:max] : nil
    Morpheus::Cli::Shell.instance.flush_history(flush_n)
    return 0
  else
    Morpheus::Cli::Shell.instance.print_history(options)
    return 0  
  end
end