/
command.rb
42 lines (34 loc) · 1.02 KB
/
command.rb
1
2
3
4
5
6
7
8
9
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
37
38
39
40
41
42
module Reviewr
module CLI
class Command
attr_reader :project
attr_accessor :input, :output
def initialize(project, input = STDIN, output = STDOUT)
@project = project
@input, @output = input, output
end
def prompt_for_user
output.print("Email (default #{project.user_email}): ")
email = input.gets.chomp
project.user_email = email unless email.empty?
output.print("Email password: ")
no_echo(input) do
project.email_password = input.gets.chomp
end
output.print("\n")
output.print("Remote repository (default origin): ")
repo = input.gets.chomp
project.remote_repo = repo unless repo.empty?
end
private
def no_echo(input)
oldt = Termios.tcgetattr(input)
newt = oldt.dup
newt.lflag &= ~Termios::ECHO
Termios.tcsetattr(input, Termios::TCSANOW, newt)
yield
Termios.tcsetattr(input, Termios::TCSANOW, oldt)
end
end
end
end