Class: Billy::Commands::Hello
Instance Method Summary
collapse
Methods inherited from Command
instance, #name, register_self!
Instance Method Details
#billy_say_hello ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/billy/commands/hello.rb', line 20
def billy_say_hello
print "Hi! I'm Billy, simple deploy tool.\n"
print "Usage:\n"
print " * billy hello (path) -- init billy in {path} folder. Inites in current if no one given.\n"
print " * billy eat {cfg_path} -- parse and save billy config in current folder. {cfg_path} here means remote file url or local one.\n"
print " * billy walk {application_name} -- deploy HEAD version in repository to remote server.\n"
end
|
#get_init_path(arguments) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/billy/commands/hello.rb', line 62
def get_init_path( arguments )
( path = arguments.shift ) unless arguments.nil?
if path.nil? || path.empty?
print "Billy will be inited in current directory. Proceed?(y/n): "
confirm = get_confirmation
if !confirm
print "Billy has nothing to do. Bye-bye."
end
path = Dir.pwd
end
File.expand_path( path )
end
|
#offer_ssh_keygen ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/billy/commands/hello.rb', line 49
def offer_ssh_keygen
print "Billy did not find your ssh key. Would you like to create it now?(y/n): "
confirm = get_confirmation
if !confirm
print "Ssh key should be generated before we continue. Please generate it.\n"
exit 1
end
enc_type = 'rsa'
print "Billy creates ssh keys for you...\n"
system "ssh-keygen -t #{enc_type} -N '' -f ~/.ssh/id_#{enc_type}"
print "All done!"
end
|
#proceed!(arguments = nil) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/billy/commands/hello.rb', line 7
def proceed!( arguments = nil )
billy_say_hello
path = get_init_path( arguments )
config = Billy::Config.instance
config.save!( path, true )
if !ssh_command_exists?
suggest_install_ssh
exit 1
end
offer_ssh_keygen unless ssh_key_exists?
print "All done!\n"
end
|
#ssh_command_exists? ⇒ Boolean
28
29
30
31
32
33
34
|
# File 'lib/billy/commands/hello.rb', line 28
def ssh_command_exists?
res = true
%w(ssh ssh-keygen).each do |cmd|
res &= system( "which #{cmd} 2>&1 > /dev/null" )
end
res
end
|
#ssh_key_exists? ⇒ Boolean
36
37
38
39
40
41
42
43
|
# File 'lib/billy/commands/hello.rb', line 36
def ssh_key_exists?
ssh_root_path = File.expand_path( "~/.ssh" )
res = true
res &= File.exists?( ssh_root_path )
res &= File.directory?( ssh_root_path )
res &= Dir[ ssh_root_path + "/*.pub" ].any?
res
end
|
#suggest_install_ssh ⇒ Object
45
46
47
|
# File 'lib/billy/commands/hello.rb', line 45
def suggest_install_ssh
print "Billy wants you to install ssh command. Please do it first.\n"
end
|