Class: Morpheus::Cli::HistoryCommand

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

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from CliCommand

#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_command_result, #parse_id_list, #parse_list_options, #parse_list_subtitles, #print, #print_error, #print_to_file, #puts, #puts_error, #raise_command_error, #render_with_format, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!

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...



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
# File 'lib/morpheus/cli/commands/standard/history_command.rb', line 13

def handle(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = "Usage: morpheus #{command_name}"
    opts.on( '-n', '--max-commands MAX', "Max Results. Default is 25" ) do |val|
      options[:max] = val
    end
    opts.add_hidden_option('-n')
    opts.on( nil, '--flush', "Flush history, purges entire shell history file." ) do |val|
      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 --flush

EOT
  end
  raw_cmd = "#{command_name} #{args.join(' ')}"
  optparse.parse!(args)
  if args.count != 0
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "wrong number of arguments, expected 0 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
    return 1
  end
  if options[:do_flush]
    unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to flush your command history?")
      return 9, "aborted command"
    end
    Morpheus::Cli::Shell.instance.flush_history
    return 0
  else
    max_commands = options[:max] || 25
    Morpheus::Cli::Shell.instance.print_history(max_commands)
    return 0  
  end
end