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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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( '-m', '--max MAX', "Max Results" ) do |max| # options[:max] = max.to_i # end # opts.on( '-o', '--offset OFFSET', "Offset Results" ) do |offset| # options[:offset] = offset.to_i.abs # end # opts.on( '-s', '--search PHRASE', "Search Phrase" ) do |phrase| # options[:phrase] = phrase # end # opts.on( '-S', '--sort ORDER', "Sort Order" ) do |v| # options[:sort] = v # end # opts.on( '-D', '--desc', "Reverse Sort Order" ) do |v| # options[:direction] = "desc" # end 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. = "Print command history.\nThe --flush option can be used to purge the history.\n\nExamples: \n history\n history -m 100\n history --flush\n\n" 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) last_cmd = Morpheus::Cli::Shell.instance.last_command # log history, but not consecutive log entries if last_cmd.nil? || last_cmd[:command] != raw_cmd Morpheus::Cli::Shell.instance.log_history_command(raw_cmd) end return 0 end end |