Sha256: f74343eff6cd425fe37c3c28c0b5e0b70676531caf52e4689d927bf80197e6a4

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'open3'

module LastpassCLI
  class Command
    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

    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

    def logout(force: true)
      args = ['logout']
      args << '--force' if force
      args
    end

    def ls(sync: 'now')
      raise unless %w[auto now no].include?(sync)
      args = ['ls', '--long']
      args << "--sync=#{sync}"
      args
    end

    def status(quiet: false)
      args = ['status']
      args << '--quiet' if quiet
      args
    end

    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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lastpass-cli-0.1.1 lib/lastpass-cli/command.rb