Class: Morpheus::Cli::HistoryCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::HistoryCommand
- Includes:
- CliCommand
- Defined in:
- lib/morpheus/cli/commands/standard/history_command.rb
Instance Attribute Summary
Attributes included from CliCommand
Instance Method Summary collapse
-
#handle(args) ⇒ Object
todo: support all the other :list options too, not just max AND start logging every terminal command, not just shell...
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) = {} optparse = Morpheus::Cli::OptionParser.new do|opts| opts. = "Usage: morpheus #{command_name}" opts.on( '-n', '--max-commands MAX', "Max Results. Default is 25" ) do |val| [:max] = val end opts.add_hidden_option('-n') opts.on( nil, '--flush', "Flush history, purges entire shell history file." ) do |val| [:do_flush] = true end (opts, , [:list, :auto_confirm]) opts. = <<-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 [:do_flush] unless [: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 = [:max] || 25 Morpheus::Cli::Shell.instance.print_history(max_commands) return 0 end end |