Module: Oplop::Cli

Defined in:
lib/oplop/cli.rb

Class Method Summary collapse

Class Method Details



6
7
8
# File 'lib/oplop/cli.rb', line 6

def self.banner
  "Usage: oplop [OPTIONS] [label]"
end

.clipboard(copy_program, string) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/oplop/cli.rb', line 44

def self.clipboard(copy_program, string)
  Open3.popen3(copy_program) do |stdin, stdout, stderr, wait_thr|
    stdin.print string
    stdin.close
    # ruby 1.9 has wait_thr, 1.8 doesn't
    if wait_thr.nil?
      !! stderr.read.strip
    else
      wait_thr.status
    end
  end
end

.copy_to_clipboard(string) ⇒ Object



38
39
40
41
42
# File 'lib/oplop/cli.rb', line 38

def self.copy_to_clipboard(string)
  copy_program = `which pbcopy`.strip
  copy_program = `which xclip`.strip if copy_program.empty?
  clipboard(copy_program, string) unless copy_program.empty?
end

.helpObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/oplop/cli.rb', line 10

def self.help
  help = "This is a simple cli program to generate oplop passwords.\n\nYou will be prompted for your master password.  \n\nThe default behavior is to copy the password to your clipboard, and\nnot display it.  This works if you are on a Mac (and/or have pbcopy \ninstalled), or if you have xclip (installed for Linux).\n\nIf you do not have pbcopy or xclip, you will have to run the program\nin verbose mode (--verbose).\n\nHere are some examples:\n\nCopy my github password to clipboard:\n  oplop github\n\nPrint my gmail password to STDOUT.\n  oplop --verbose gmail\n\nCopy a new password for amazon (prompts for master twice):\n  oplop --new amazon\n\nFeedback, patches and bugs: https://github.com/bkaney/oplop\n"
end