module LastpassCLI

Constants

VERSION

Public Class Methods

add_note(name, note_type: nil, notes: nil, data: {}) click to toggle source
# File lib/lastpass-cli.rb, line 58
def self.add_note(name, note_type: nil, notes: nil, data: {})
  stdin_data = ""
  data.each do |field, value|
    stdin_data << "#{field.capitalize}:#{value}\n"
  end
  stdin_data << "Notes:\n#{notes}\n"
  Command.run(Command.new.add(name: name, note_type: note_type), stdin_data: stdin_data)
end
add_password(name, username:, password:, notes: nil, url: nil) click to toggle source
# File lib/lastpass-cli.rb, line 50
def self.add_password(name, username:, password:, notes: nil, url: nil)
  stdin_data = "Username:#{username}\nPassword:#{password}\n"
  stdin_data << "URL:#{url}\n" if url
  stdin_data << "Notes:\n#{notes}\n" if notes
  Command.run(Command.new.add(name: name), stdin_data: stdin_data)
  show(name)
end
configuration() click to toggle source
# File lib/lastpass-cli.rb, line 8
def self.configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/lastpass-cli.rb, line 16
def self.configure
  yield(configuration)
end
items() click to toggle source
# File lib/lastpass-cli.rb, line 20
def self.items
  items = []
  out = Command.run(Command.new.ls)
  if !out.nil? && out != ""
    out.each_line do |line|
      match_data = line.match(/(?<modified_at>\d{4}-\d{2}-\d{2} \d{2}:\d{2}) (?<folder>.+)\/(?<name>.+) \[id: (?<id>.*)\] \[username:\s?(?<username>.+)\]/)
      attributes = Hash[match_data.names.zip(match_data.captures)]
      items << Item.new(attributes)
    end
  end
  items
end
reset_configuration!() click to toggle source
# File lib/lastpass-cli.rb, line 12
def self.reset_configuration!
  @configuration = Configuration.new
end
show(name) click to toggle source
# File lib/lastpass-cli.rb, line 33
def self.show(name)
  items = []
  out = Command.run(Command.new.show(name: name))
  if !out.nil? && out != "" && !out.start_with?("Error: ")
    out.each_line do |line|
      id_match = line.match(/^((?<folder>.*)\/)?(?<name>.*) \[id: (?<id>.*)\]/)
      if id_match
        items << Item.new(id: id_match[:id], folder: id_match[:folder], name: id_match[:name])
      else
        match_data = line.match(/^(?<key>.*): (?<value>.*)$/)
        items.last.set(match_data[:key].downcase, match_data[:value])
      end
    end
  end
  items
end