Top Level Namespace

Defined Under Namespace

Classes: Trocla

Instance Method Summary collapse

Instance Method Details

#check_format(format_name) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'bin/trocla', line 112

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



49
50
51
52
53
54
55
# File 'bin/trocla', line 49

def create(options)
  [ Trocla.new(options.delete(:config_file)).password(
    options.delete(:trocla_key),
    options.delete(:trocla_format),
    options.merge(YAML.load(options.delete(:other_options).shift.to_s)||{})
  ) , 0 ]
end

#delete(options) ⇒ Object



101
102
103
104
105
106
# File 'bin/trocla', line 101

def delete(options)
  [ Trocla.new(options.delete(:config_file)).delete_password(
    options.delete(:trocla_key),
    options.delete(:trocla_format)
  ), 0 ]
end

#formats(options) ⇒ Object



108
109
110
# File 'bin/trocla', line 108

def formats(options)
  "Available formats: #{Trocla::Formats.all.join(', ')}"
end

#get(options) ⇒ Object



57
58
59
60
61
62
63
64
# File 'bin/trocla', line 57

def get(options)
  res = Trocla.new(options.delete(:config_file)).get_password(
    options.delete(:trocla_key),
    options.delete(:trocla_format),
    options.merge(YAML.load(options.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(options)
  [ Trocla.new(options.delete(:config_file)).reset_password(
    options.delete(:trocla_key),
    options.delete(:trocla_format),
    options.merge(YAML.load(options.delete(:other_options).shift.to_s)||{})
  ), 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(options)
  if options.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 = options.delete(:password) || STDIN.read.chomp
  end
  format = options.delete(:trocla_format)
  no_format = options.delete('no_format')
  trocla = Trocla.new(options.delete(:config_file))
  value = if no_format
    password
  else
    trocla.formats(format).format(password, (YAML.load(options.delete(:other_options).shift.to_s)||{}))
  end
  trocla.set_password(
    options.delete(:trocla_key),
    format,
    value
  )
  [ '', 0 ]
end