Class: KBSecret::CLI::Command::List
- Defined in:
- lib/kbsecret/cli/command/list.rb
Overview
The implementation of kbsecret list
.
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#initialize(argv) ⇒ List
constructor
A new instance of List.
- #run! ⇒ Object
- #setup! ⇒ Object
- #validate! ⇒ Object
Methods inherited from Abstract
Constructor Details
#initialize(argv) ⇒ List
Returns a new instance of List.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kbsecret/cli/command/list.rb', line 8 def initialize(argv) super(argv) do |cli| cli.slop do |o| o. = " Usage:\n kbsecret list [options]\n HELP\n\n o.string \"-s\", \"--session\", \"the session to list from\", default: :default\n o.string \"-t\", \"--type\", \"the type of secrets to list\", default: nil\n o.bool \"-a\", \"--show-all\", \"show everything in each secret (i.e. metadata)\"\n o.bool \"-D\", \"--sort-date\", \"sort records by date (oldest to newest)\"\n o.bool \"-A\", \"--sort-alphabetical\", \"sort records by label\"\n end\n\n cli.ensure_type! if cli.opts[:type]\n cli.ensure_session!\n end\nend\n" |
Instance Method Details
#run! ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kbsecret/cli/command/list.rb', line 41 def run! if cli.opts.sort_date? @records.sort_by!(&:timestamp) elsif cli.opts.sort_alphabetical? @records.sort_by!(&:label) end @records.each do |record| puts record.label next unless cli.opts.show_all? puts " \\tType: \#{record.type}\n \\tLast changed: \#{Time.at(record.timestamp)}\n \\tRaw data: \#{record.data}\n DETAIL\n end\nend\n" |
#setup! ⇒ Object
29 30 31 |
# File 'lib/kbsecret/cli/command/list.rb', line 29 def setup! @records = cli.session.records TYPE_ALIASES[cli.opts[:type]] end |
#validate! ⇒ Object
34 35 36 37 38 |
# File 'lib/kbsecret/cli/command/list.rb', line 34 def validate! if cli.opts.sort_date? && cli.opts.sort_alphabetical? cli.die "Only one sort flag may be used at once." end end |