Top Level Namespace
Defined Under Namespace
Classes: Trocla
Instance Method Summary collapse
- #check_format(format_name) ⇒ Object
- #create(options) ⇒ Object
- #delete(options) ⇒ Object
- #formats(options) ⇒ Object
- #get(options) ⇒ Object
- #reset(options) ⇒ Object
- #search(options) ⇒ Object
- #set(options) ⇒ Object
Instance Method Details
#check_format(format_name) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'bin/trocla', line 129 def check_format(format_name) if format_name.nil? STDERR.puts 'Missing format, exiting...' exit 1 elsif !Trocla::Formats.available?(format_name) STDERR.puts "Error: The format #{format_name} is not available" exit 1 end end |
#create(options) ⇒ Object
48 49 50 51 52 53 54 |
# File 'bin/trocla', line 48 def create() [Trocla.new(.delete(:config_file)).password( .delete(:trocla_key), .delete(:trocla_format), .merge(YAML.safe_load(.delete(:other_options).shift.to_s) || {}) ), 0] end |
#delete(options) ⇒ Object
101 102 103 104 105 106 107 |
# File 'bin/trocla', line 101 def delete() res = Trocla.new(.delete(:config_file)).delete_password( .delete(:trocla_key), .delete(:trocla_format) ) [res, res.nil? ? 1 : 0] end |
#formats(options) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'bin/trocla', line 109 def formats() key = (.delete(:trocla_key) || '') if key.empty? "Available formats: #{Trocla::Formats.all.join(', ')}" else res = Trocla.new(.delete(:config_file)).available_format( key, .merge(YAML.safe_load(.delete(:other_options).shift.to_s) || {}) ) [res.nil? ? res : res.join(', '), res.nil? ? 1 : 0] end end |
#get(options) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'bin/trocla', line 56 def get() res = Trocla.new(.delete(:config_file)).get_password( .delete(:trocla_key), .delete(:trocla_format), .merge(YAML.safe_load(.delete(:other_options).shift.to_s) || {}) ) [res, res.nil? ? 1 : 0] end |
#reset(options) ⇒ Object
93 94 95 96 97 98 99 |
# File 'bin/trocla', line 93 def reset() [Trocla.new(.delete(:config_file)).reset_password( .delete(:trocla_key), .delete(:trocla_format), .merge(YAML.safe_load(.delete(:other_options).shift.to_s) || {}) ), 0] end |
#search(options) ⇒ Object
122 123 124 125 126 127 |
# File 'bin/trocla', line 122 def search() res = Trocla.new(.delete(:config_file)).search_key( .delete(:trocla_key) ) [res.nil? ? res : res.join("\n"), res.nil? ? 1 : 0] end |
#set(options) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'bin/trocla', line 65 def set() if .delete(:ask_password) require 'highline/import' password = ask('Enter your password: ') { |q| q.echo = 'x' }.to_s pwd2 = ask('Repeat password: ') { |q| q.echo = 'x' }.to_s unless password == pwd2 STDERR.puts 'Passwords did not match, exiting!' return [nil, 1] end else password = .delete(:password) || STDIN.read.chomp end format = .delete(:trocla_format) no_format = .delete('no_format') trocla = Trocla.new(.delete(:config_file)) value = if no_format password else trocla.formats(format).format(password, (YAML.safe_load(.delete(:other_options).shift.to_s) || {})) end trocla.set_password( .delete(:trocla_key), format, value ) ['', 0] end |