Class: Omnivault::CLI
- Inherits:
-
Thor
- Object
- Thor
- Omnivault::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/omnivault/cli.rb
Class Method Summary collapse
- .default_option_desc ⇒ Object
- .default_options ⇒ Object
-
.exit_on_failure? ⇒ Boolean
Forward return codes on failures.
Instance Method Summary collapse
Class Method Details
.default_option_desc ⇒ Object
18 19 20 |
# File 'lib/omnivault/cli.rb', line 18 def self.default_option_desc '[-v VAULT]' end |
.default_options ⇒ Object
14 15 16 |
# File 'lib/omnivault/cli.rb', line 14 def self. option :vault, aliases: '-v', default: 'default' end |
.exit_on_failure? ⇒ Boolean
Forward return codes on failures.
10 11 12 |
# File 'lib/omnivault/cli.rb', line 10 def self.exit_on_failure? true end |
Instance Method Details
#env ⇒ Object
51 52 53 54 55 |
# File 'lib/omnivault/cli.rb', line 51 def env vault_by_name([:vault]).entries.each do |key, value| say "#{key}=#{Shellwords.escape(value)}" end end |
#exec(*args) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/omnivault/cli.rb', line 60 def exec(*args) vault_by_name([:vault]).entries.each do |key, value| ENV[key] = value end system(*args) end |
#ls ⇒ Object
70 71 72 73 74 |
# File 'lib/omnivault/cli.rb', line 70 def ls vault_by_name([:vault]).entries.keys.each do |key| say key end end |
#set(*args) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/omnivault/cli.rb', line 25 def set(*args) raise ArgumentError, 'Wrong number of arguments' if args.empty? hash = Hash[args.map { |arg| arg.split('=', 2) }] hash.each do |key, value| vault_by_name([:vault]).store(key, value) end end |
#unset(*args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/omnivault/cli.rb', line 37 def unset(*args) raise ArgumentError, 'Wrong number of arguments' if args.empty? vault = vault_by_name([:vault]) missing = args - vault.entries.keys raise Thor::Error, "Keys not found: #{missing.join(', ')}" if missing.any? args.each do |key| vault.remove(key) end end |