morpheus-cli 3.6.16 → 3.6.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2965857867a8deda2e9e0c8e6033823838c48710cde42a3d6f27b0ee5287faa6
4
- data.tar.gz: f16690f4f149d1f17814059ae6e385bc9fe550964044c9deecf54e352c7e333e
3
+ metadata.gz: 1ab0c8fe5a857968851e03071645663f2c0ca449577b3c2e62106ed9ef57c9fe
4
+ data.tar.gz: 85e741a356d27d1729eb9e51cd9be7aebe7b3f9d11f17132f342992131b6c7d7
5
5
  SHA512:
6
- metadata.gz: 580ca508572a8f69dc7d14626cf24df8fac27f148041272d01a71b943a256fe283ba880141685d243fb08bdb5b82a41f40bd80fd91d8d92227699901401552f2
7
- data.tar.gz: 6852abdd9d76fa2f3a20e8e1b268eb3012c08906c02c5404a6fdc33378427036a2dbe66df5000bfa78339e8a10307d3020435cb17fbcc4dffd6171037cb2d53d
6
+ metadata.gz: 9780024822d8ff3eda9cb7ce718f3bd0fe18975e97ba6a883e88d22d4c311b72d8e2eba0de07ec265fb4789391ba3ea004737072a8b13bebb85f2a198c9d5631
7
+ data.tar.gz: 3dbdd462ee7e562561ba0d3ec94cb7fd96a2af842b610f04e3524301136ac80dd9c7d33b79cc87b0e2fdb99a3ebc33c3c0cd85986ae4da4bcbe090c1f3945e6c
@@ -46,7 +46,8 @@ EOT
46
46
  return 1
47
47
  end
48
48
  if options[:do_flush]
49
- unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to flush your command history?")
49
+ command_count = Morpheus::Cli::Shell.instance.history_commands_count
50
+ 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'})?")
50
51
  return 9, "aborted command"
51
52
  end
52
53
  Morpheus::Cli::Shell.instance.flush_history
@@ -723,8 +723,8 @@ class Morpheus::Cli::Shell
723
723
  # @return Hash like {:commands => [], :command_count => total}
724
724
  def load_history_commands(options={})
725
725
  phrase = options[:phrase]
726
- sort = options[:sort] ? options[:sort].to_sym : :number
727
- direction = options[:direction] == 'desc' ? 'desc' : 'asc'
726
+ sort_key = options[:sort] ? options[:sort].to_sym : nil
727
+
728
728
  offset = options[:offset].to_i > 0 ? options[:offset].to_i : 0
729
729
  max = options[:max].to_i > 0 ? options[:max].to_i : 25
730
730
 
@@ -739,15 +739,15 @@ class Morpheus::Cli::Shell
739
739
 
740
740
  # sort is a bit different for this command, the default sort is by number
741
741
  # it sorts oldest -> newest, but shows the very last page by default.
742
- sort_key = :number
743
- if sort.to_sym == :command
744
- sort_key = :command
742
+ if options[:sort] && ![:number, :command].include?(options[:sort])
743
+ options[:sort] = nil
745
744
  end
746
745
 
747
- if phrase || sort_key != :number
746
+
747
+ if options[:phrase] || sort_key || options[:direction] || options[:offset]
748
748
  # this could be a large object...need to index our shell_history file lol
749
749
  history_records = @history.keys.collect { |k| {number: k, command: @history[k]} }
750
- if direction == 'desc'
750
+ if options[:direction] == 'desc'
751
751
  history_records = history_records.sort {|x,y| y[sort_key] <=> x[sort_key] }
752
752
  else
753
753
  history_records = history_records.sort {|x,y| x[sort_key] <=> y[sort_key] }
@@ -756,26 +756,20 @@ class Morpheus::Cli::Shell
756
756
  history_records = history_records.select {|it| it[:command].include?(phrase) || it[:number].to_s == phrase }
757
757
  end
758
758
  command_count = history_records.size
759
- history_records = history_records[offset..max-1]
759
+ history_records = history_records[offset..(max-1)]
760
760
  else
761
761
  # default should try to be as fast as possible..
762
762
  # no searching or sorting, default order by :number works
763
- # desc here means show oldest commands
764
- cmd_count = @history.keys.size
765
- cmd_numbers = []
766
- if direction == 'desc'
767
- cmd_numbers = @history.keys[offset..(offset + max-1)]
763
+ if offset != 0
764
+ cmd_numbers = @history.keys.last(max + offset).first(max)
768
765
  else
769
- if offset != 0
770
- cmd_numbers = @history.keys.last(max + offset).first(max)
771
- else
772
- cmd_numbers = @history.keys.last(max)
773
- end
774
- history_records = cmd_numbers.collect { |k| {number: k, command: @history[k]} }
775
- command_count = @history.size
766
+ cmd_numbers = @history.keys.last(max)
776
767
  end
768
+ history_records = cmd_numbers.collect { |k| {number: k, command: @history[k]} }
769
+ command_count = @history.size
777
770
  end
778
- return {:commands => history_records, :command_count => command_count}
771
+ meta = {size:history_records.size, total:command_count.to_i, max:max, offset:offset}
772
+ return {:commands => history_records, :command_count => command_count, :meta => meta}
779
773
  end
780
774
 
781
775
  def print_history(options={})
@@ -794,7 +788,12 @@ class Morpheus::Cli::Shell
794
788
  puts "#{history_record[:number].to_s.rjust(3, ' ')} #{history_record[:command]}"
795
789
  end
796
790
  if options[:show_pagination]
797
- print_results_pagination({size:history_records.size,total:command_count.to_i})
791
+ if options[:phrase] || options[:sort] || options[:direction] || options[:offset]
792
+ print_results_pagination({:meta => history_result[:meta]})
793
+ else
794
+ # default order is weird, it's the last page of results, 1-25 is misleading and showing the indexes is stranger
795
+ print_results_pagination({:meta => history_result[:meta]}, {:message =>"Viewing most recent %{size} of %{total} %{label}"})
796
+ end
798
797
  print reset, "\n"
799
798
  end
800
799
  end
@@ -816,7 +815,7 @@ class Morpheus::Cli::Shell
816
815
  @history = {}
817
816
  @last_command_number = 0
818
817
  @history_logger = load_history_logger
819
- print cyan, "Command history flushed!", reset, "\n"
818
+ print green, "Command history flushed", reset, "\n"
820
819
  return 0
821
820
  end
822
821
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Morpheus
3
3
  module Cli
4
- VERSION = "3.6.16"
4
+ VERSION = "3.6.17"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morpheus-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.16
4
+ version: 3.6.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Estes
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-02-27 00:00:00.000000000 Z
14
+ date: 2019-02-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler