class LastpassCLI::Command

Public Class Methods

run(args, stdin_data: nil) click to toggle source
# File lib/lastpass-cli/command.rb, line 5
def self.run(args, stdin_data: nil)
  raise unless Agent.new.login
  command = [LastpassCLI.configuration.executable]
  command += args
  out, _, _ = Open3.capture2e(*command, stdin_data: stdin_data)
  out
rescue StandardError => e
  raise "Failed to execute:\n#{command}\nError: #{e}"
end

Public Instance Methods

add(name:, sync: 'now', note_type: nil) click to toggle source
# File lib/lastpass-cli/command.rb, line 50
def add(name:, sync: 'now', note_type: nil)
  raise unless %w[auto now no].include?(sync)
  args = ['add', '--non-interactive']
  args << "--sync=#{sync}"
  args << "--note-type=#{note_type}" if note_type
  args << name
end
login(username:, trust: false, plaintext_key: false, force: false) click to toggle source
# File lib/lastpass-cli/command.rb, line 15
def login(username:, trust: false, plaintext_key: false, force: false)
  args = ['login', username]
  args << '--plaintext-key' if plaintext_key
  args << '--force' if force
  args
end
logout(force: true) click to toggle source
# File lib/lastpass-cli/command.rb, line 22
def logout(force: true)
  args = ['logout']
  args << '--force' if force
  args
end
ls(sync: 'now') click to toggle source
# File lib/lastpass-cli/command.rb, line 28
def ls(sync: 'now')
  raise unless %w[auto now no].include?(sync)
  args = ['ls', '--long']
  args << "--sync=#{sync}"
  args
end
show(name:, sync: 'now', expand_multi: true) click to toggle source
# File lib/lastpass-cli/command.rb, line 41
def show(name:, sync: 'now', expand_multi: true)
  raise unless %w[auto now no].include?(sync)
  args = ['show', '--all']
  args << "--sync=#{sync}"
  args << '--expand-multi' if expand_multi
  args << name
  args
end
status(quiet: false) click to toggle source
# File lib/lastpass-cli/command.rb, line 35
def status(quiet: false)
  args = ['status']
  args << '--quiet' if quiet
  args
end